diff --git a/src/renderer/src/components/terminal-pane/pty-connection.ts b/src/renderer/src/components/terminal-pane/pty-connection.ts index ae6a81782..66e7e5f66 100644 --- a/src/renderer/src/components/terminal-pane/pty-connection.ts +++ b/src/renderer/src/components/terminal-pane/pty-connection.ts @@ -1247,14 +1247,9 @@ export function connectPanePty( ) return tab?.defaultTitle?.trim() || 'Terminal' } - /** - * Resolves the authoritative owner agent type for this pane, checking tab launch, - * pane startup, typed command ownership, and store state configuration. - * - * Why: launch ownership wins so Pi-compatible live titles/hooks can't repaint an - * OMP-owned pane back to Pi; command ownership covers manually typed `omp` - * in generic terminals where launch metadata does not exist. - */ + // Why: infer pane ownership from a manually typed agent command (e.g. `omp`) by + // shadowing the shell's current command line, for generic terminals where no + // launch metadata exists. Consumed by getAuthoritativePaneAgent below. let commandInferredPaneAgent: TuiAgent | null = null let pendingShellCommandLine = '' let pendingShellCommandCursor = 0 @@ -1355,9 +1350,13 @@ export function connectPanePty( return null } const params = data.slice(index + 2, cursor) - if (final === 'D') { + // Why: only emulate a bare one-column move. Parameterized/modified cursor keys + // (e.g. Ctrl+Left `\x1b[1;5D` = word-jump) move the real cursor by more than + // one, so tracking them as ±1 would desync the shadow line — fall through to + // reset instead of silently corrupting the sampled command. + if (final === 'D' && params === '') { movePendingShellCommandCursor(-1) - } else if (final === 'C') { + } else if (final === 'C' && params === '') { movePendingShellCommandCursor(1) } else if (final === 'H' || (final === '~' && params === '1')) { pendingShellCommandCursor = 0 @@ -1462,6 +1461,14 @@ export function connectPanePty( } } } + /** + * Resolves the authoritative owner agent type for this pane, checking tab launch, + * pane startup, typed command ownership, and store state configuration. + * + * Why: launch ownership wins so Pi-compatible live titles/hooks can't repaint an + * OMP-owned pane back to Pi; command ownership covers manually typed `omp` + * in generic terminals where launch metadata does not exist. + */ const getAuthoritativePaneAgent = (): AgentType | undefined => { const state = useAppStore.getState() const tab = (state.tabsByWorktree[deps.worktreeId] ?? []).find( diff --git a/src/renderer/src/components/terminal-pane/terminal-link-activation.ts b/src/renderer/src/components/terminal-pane/terminal-link-activation.ts index e85da9032..41def2095 100644 --- a/src/renderer/src/components/terminal-pane/terminal-link-activation.ts +++ b/src/renderer/src/components/terminal-pane/terminal-link-activation.ts @@ -1,6 +1,7 @@ +import { isMacPlatform } from './terminal-link-open-hints' + export function isTerminalLinkActivation( event: Pick | undefined ): boolean { - const isMac = navigator.userAgent.includes('Mac') - return isMac ? Boolean(event?.metaKey) : Boolean(event?.ctrlKey) + return isMacPlatform() ? Boolean(event?.metaKey) : Boolean(event?.ctrlKey) } diff --git a/src/renderer/src/lib/pane-manager/pane-split-close.ts b/src/renderer/src/lib/pane-manager/pane-split-close.ts index b7d8356e0..4bc601837 100644 --- a/src/renderer/src/lib/pane-manager/pane-split-close.ts +++ b/src/renderer/src/lib/pane-manager/pane-split-close.ts @@ -166,7 +166,7 @@ type CloseManagedPaneArgs = { setActivePaneId: (paneId: number | null) => void } -export function closeManagedPane(args: CloseManagedPaneArgs): void { +function teardownManagedPane(args: CloseManagedPaneArgs, reason: 'close' | 'detach'): void { const pane = args.panes.get(args.paneId) if (!pane) { return @@ -183,33 +183,24 @@ export function closeManagedPane(args: CloseManagedPaneArgs): void { args.managerOptions.onPaneClosed?.(args.paneId, { paneId: args.paneId, leafId: closedLeafId, - reason: 'close' + reason }) args.managerOptions.onLayoutChanged?.() } +export function closeManagedPane(args: CloseManagedPaneArgs): void { + teardownManagedPane(args, 'close') +} + export function detachManagedPaneForExternalMove(args: CloseManagedPaneArgs): boolean { - const pane = args.panes.get(args.paneId) - if (!pane || args.panes.size <= 1) { + // Why: refuse to detach the last pane — there is no other pane to fall back to. + if (!args.panes.has(args.paneId) || args.panes.size <= 1) { return false } - const closedLeafId = pane.leafId - args.releasePaneIdentity(args.paneId) - removePaneContainer(args, pane) - const nextActivePaneId = activateReplacementPane(args) - applyPaneOpacity(args.panes.values(), nextActivePaneId, args.styleOptions) - for (const p of args.panes.values()) { - safeFit(p) - } - updateMultiPaneState(args.getDragCallbacks()) // Why: pane-to-tab detach tears down only this renderer pane; the PTY is - // adopted by the new tab, so TerminalPane must skip process-close cleanup. - args.managerOptions.onPaneClosed?.(args.paneId, { - paneId: args.paneId, - leafId: closedLeafId, - reason: 'detach' - }) - args.managerOptions.onLayoutChanged?.() + // adopted by the new tab, so the 'detach' reason tells TerminalPane to skip + // process-close cleanup. + teardownManagedPane(args, 'detach') return true }