mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 20:23:36 +00:00
fix: address PR review comments
- Add nonce parameter to terminal navigation to allow reopening same worktree multiple times - Fix shell path escaping in editor.ts using single-quote wrapper - Add validatePathParams middleware to open-in-external-terminal route - Remove redundant validation block from createOpenInExternalTerminalHandler - Remove unused pendingTerminal state and setPendingTerminal action - Remove unused getTerminalInfo function from editor.ts
This commit is contained in:
@@ -131,9 +131,10 @@ export function useWorktreeActions({ fetchWorktrees, fetchBranches }: UseWorktre
|
||||
(worktree: WorktreeInfo, mode?: 'tab' | 'split') => {
|
||||
// Navigate to the terminal view with the worktree path and branch name
|
||||
// The terminal view will handle creating the terminal with the specified cwd
|
||||
// Include nonce to allow opening the same worktree multiple times
|
||||
navigate({
|
||||
to: '/terminal',
|
||||
search: { cwd: worktree.path, branch: worktree.branch, mode },
|
||||
search: { cwd: worktree.path, branch: worktree.branch, mode, nonce: Date.now() },
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
|
||||
@@ -224,9 +224,11 @@ interface TerminalViewProps {
|
||||
initialBranch?: string;
|
||||
/** Mode for opening terminal: 'tab' for new tab, 'split' for split in current tab */
|
||||
initialMode?: 'tab' | 'split';
|
||||
/** Unique nonce to allow opening the same worktree multiple times */
|
||||
nonce?: number;
|
||||
}
|
||||
|
||||
export function TerminalView({ initialCwd, initialBranch, initialMode }: TerminalViewProps) {
|
||||
export function TerminalView({ initialCwd, initialBranch, initialMode, nonce }: TerminalViewProps) {
|
||||
const {
|
||||
terminalState,
|
||||
setTerminalUnlocked,
|
||||
@@ -556,9 +558,9 @@ export function TerminalView({ initialCwd, initialBranch, initialMode }: Termina
|
||||
// Skip if no initialCwd provided
|
||||
if (!initialCwd) return;
|
||||
|
||||
// Skip if we've already handled this exact cwd (prevents duplicate terminals)
|
||||
// Include mode in the key to allow opening same cwd with different modes
|
||||
const cwdKey = `${initialCwd}:${initialMode || 'default'}`;
|
||||
// Skip if we've already handled this exact request (prevents duplicate terminals)
|
||||
// Include mode and nonce in the key to allow opening same cwd multiple times
|
||||
const cwdKey = `${initialCwd}:${initialMode || 'default'}:${nonce || 0}`;
|
||||
if (initialCwdHandledRef.current === cwdKey) return;
|
||||
|
||||
// Skip if terminal is not enabled or not unlocked
|
||||
@@ -632,6 +634,7 @@ export function TerminalView({ initialCwd, initialBranch, initialMode }: Termina
|
||||
initialCwd,
|
||||
initialBranch,
|
||||
initialMode,
|
||||
nonce,
|
||||
status?.enabled,
|
||||
status?.passwordRequired,
|
||||
terminalState.isUnlocked,
|
||||
|
||||
@@ -6,6 +6,7 @@ const terminalSearchSchema = z.object({
|
||||
cwd: z.string().optional(),
|
||||
branch: z.string().optional(),
|
||||
mode: z.enum(['tab', 'split']).optional(),
|
||||
nonce: z.number().optional(),
|
||||
});
|
||||
|
||||
export const Route = createFileRoute('/terminal')({
|
||||
@@ -14,6 +15,6 @@ export const Route = createFileRoute('/terminal')({
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const { cwd, branch, mode } = Route.useSearch();
|
||||
return <TerminalView initialCwd={cwd} initialBranch={branch} initialMode={mode} />;
|
||||
const { cwd, branch, mode, nonce } = Route.useSearch();
|
||||
return <TerminalView initialCwd={cwd} initialBranch={branch} initialMode={mode} nonce={nonce} />;
|
||||
}
|
||||
|
||||
@@ -531,7 +531,6 @@ export interface TerminalState {
|
||||
lineHeight: number; // Line height multiplier for terminal text
|
||||
maxSessions: number; // Maximum concurrent terminal sessions (server setting)
|
||||
lastActiveProjectPath: string | null; // Last project path to detect route changes vs project switches
|
||||
pendingTerminal: { cwd: string; branchName: string } | null; // Pending terminal to create (from "open in terminal" action)
|
||||
openTerminalMode: 'newTab' | 'split'; // How to open terminals from "Open in Terminal" action
|
||||
}
|
||||
|
||||
@@ -1239,7 +1238,6 @@ export interface AppActions {
|
||||
setTerminalLineHeight: (lineHeight: number) => void;
|
||||
setTerminalMaxSessions: (maxSessions: number) => void;
|
||||
setTerminalLastActiveProjectPath: (projectPath: string | null) => void;
|
||||
setPendingTerminal: (pending: { cwd: string; branchName: string } | null) => void;
|
||||
setOpenTerminalMode: (mode: 'newTab' | 'split') => void;
|
||||
addTerminalTab: (name?: string) => string;
|
||||
removeTerminalTab: (tabId: string) => void;
|
||||
@@ -1459,7 +1457,6 @@ const initialState: AppState = {
|
||||
lineHeight: 1.0,
|
||||
maxSessions: 100,
|
||||
lastActiveProjectPath: null,
|
||||
pendingTerminal: null,
|
||||
openTerminalMode: 'newTab',
|
||||
},
|
||||
terminalLayoutByProject: {},
|
||||
@@ -2912,9 +2909,6 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
|
||||
maxSessions: current.maxSessions,
|
||||
// Preserve lastActiveProjectPath - it will be updated separately when needed
|
||||
lastActiveProjectPath: current.lastActiveProjectPath,
|
||||
// Preserve pendingTerminal - this is set by "open in terminal" action and should
|
||||
// survive the clearTerminalState() call that happens during project switching
|
||||
pendingTerminal: current.pendingTerminal,
|
||||
// Preserve openTerminalMode - user preference
|
||||
openTerminalMode: current.openTerminalMode,
|
||||
},
|
||||
@@ -3008,13 +3002,6 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
|
||||
});
|
||||
},
|
||||
|
||||
setPendingTerminal: (pending) => {
|
||||
const current = get().terminalState;
|
||||
set({
|
||||
terminalState: { ...current, pendingTerminal: pending },
|
||||
});
|
||||
},
|
||||
|
||||
setOpenTerminalMode: (mode) => {
|
||||
const current = get().terminalState;
|
||||
set({
|
||||
|
||||
Reference in New Issue
Block a user