Skip to content

fix: terminal shortcuts firing in wrong worktree - #542

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/split-pane-issue
Apr 12, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/split-pane-issue

Conversation

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Summary

  • Split pane in wrong worktree: Hidden (but mounted) worktrees kept their focusedGroupId, so their TerminalPanes registered window-level keydown handlers alongside the visible worktree's. Cmd+D, Cmd+W, etc. fired in all worktrees because stopPropagation doesn't block sibling listeners on the same target.
  • Duplicate close dialog: Same root cause — multiple closeActivePane handlers fired, showing the confirmation modal multiple times.
  • Auto-recreating tabs on close: The auto-create-first-tab effect couldn't distinguish "worktree just activated with no tabs" from "user closed the last tab", so it spawned a replacement terminal immediately after every close.

Changes

  • Terminal.tsx: Pass focusedGroupId={undefined} for hidden worktrees so their TerminalPanes get isActive=false and never register keyboard handlers.
  • keyboard-handlers.ts: Upgrade all stopPropagation() → stopImmediatePropagation() as defense-in-depth, so even if multiple handlers are active on window, only the first one processes the event.
  • Terminal.tsx: Replace single-value initialTabCreationGuardRef with a Set<string> tracking initialized worktrees. Once a worktree has had tabs, closing all of them won't auto-spawn a replacement.

Test plan

  • Open two worktrees, switch between them, then Cmd+D in the active one — split should only appear in the visible worktree
  • Split a pane, then Cmd+W — close dialog should appear at most once (only if a process is running)
  • Close the last terminal tab (idle shell) — no replacement tab should auto-spawn
  • Activate a brand-new worktree with no tabs — first terminal should still auto-create
  • Cmd+T still creates new tabs in an empty worktree

…tabs

Hidden worktrees kept their focusedGroupId, so their TerminalPanes
registered window-level keydown handlers alongside the visible
worktree's. All handlers fired on every shortcut because
stopPropagation does not block sibling listeners on the same target.

- Pass focusedGroupId as undefined for hidden worktrees so their
  TerminalPanes never get isActive=true
- Upgrade all stopPropagation to stopImmediatePropagation as
  defense-in-depth
- Replace single-value auto-create guard with a Set so closing the
  last tab no longer spawns a replacement terminal
@Jinwoo-H
Jinwoo-H merged commit 0a6ab88 into main Apr 12, 2026
1 check passed
brennanb2025 added a commit that referenced this pull request Apr 12, 2026
brennanb2025 added a commit that referenced this pull request Apr 12, 2026
Reapplies the fixes from #542 which were reverted in #546 as part of
the #520 revert chain.

- Replace single-value initialTabCreationGuardRef with a Set so
  closing the last tab no longer auto-spawns a replacement terminal
- Upgrade all stopPropagation to stopImmediatePropagation as
  defense-in-depth against duplicate window-level keydown handlers

The focusedGroupId change from #542 is omitted because it targeted
TabGroupSplitLayout from #520, which remains reverted. The current
code already gates isActive on isVisible, providing the same
protection.
brennanb2025 added a commit that referenced this pull request Apr 19, 2026
Adds Playwright coverage for two high-regression areas identified from the
last 200 PRs:

- worktree-lifecycle.spec.ts: guards removeWorktree cleanup (#532),
  worktree switch with right sidebar open (#598/#628/#726), and
  cross-worktree tab isolation (#542/#554).
- tab-close-navigation.spec.ts: guards visual-neighbor activation on
  editor/diff close (#693) and Landing fallback when the last visible
  surface closes (#677).
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant