Skip to content

Fix tab switching after terminal tab reorder - #6395

Merged
Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/fix-terminal-reorder-tab-switch
Jun 26, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
Jinwoo-H/fix-terminal-reorder-tab-switch

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Why

The broken release repro is: drag a terminal tab to reorder it with another terminal tab, then tab clicks stop switching and feel like drag attempts. The delayed pointer-up activation introduced in #5927 made tab activation depend on dnd-kit drag-state cleanup. That coupling was fragile; the #6392 fallback was not enough once the actual repro was a completed terminal reorder.

This PR goes back to the older, simpler behavior: clicking/pressing a tab activates it immediately, then dnd-kit can continue handling the drag gesture.

Verification

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/tab-bar/BrowserTab.test.tsx src/renderer/src/components/tab-bar/EditorFileTab.test.tsx src/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsx src/renderer/src/components/tab-bar/drop-indicator.test.ts
  • pnpm exec oxlint src/renderer/src/components/tab-bar/BrowserTab.tsx src/renderer/src/components/tab-bar/BrowserTab.test.tsx src/renderer/src/components/tab-bar/EditorFileTab.tsx src/renderer/src/components/tab-bar/EditorFileTab.test.tsx src/renderer/src/components/tab-bar/SortableTab.tsx src/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsx src/renderer/src/components/tab-bar/drop-indicator.ts src/renderer/src/components/tab-bar/drop-indicator.test.ts tests/e2e/tabs.spec.ts
  • pnpm run typecheck:web
  • pnpm exec playwright test tests/e2e/tabs.spec.ts --config tests/playwright.config.ts --project electron-headless --grep "clicking tabs still switches after dragging a terminal tab to reorder" --workers=1

Made with Orca 🐋

@Jinwoo-H
Jinwoo-H force-pushed the Jinwoo-H/fix-terminal-reorder-tab-switch branch from aeee492 to c569738 Compare June 26, 2026 01:25
@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The tab bar components remove the pointer-activation hook and selection-chrome helper, change tab root styling to depend on isActive, and update pointer handling to activate on primary clicks before forwarding drag events. Related unit tests, tab insertion edge tests, and the tab reorder E2E test were updated to match the new interaction flow and DOM assertions.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, rationale, and verification, but it omits several required template sections like screenshots, AI review report, security audit, and notes. Add the missing template sections and include screenshots or state no visual change, a testing checklist, an AI review report, a security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main user-facing change: fixing tab switching after terminal tab reorder.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/tab-bar/BrowserTab.tsx (1)

180-186: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add a short "why" comment for the pointer-down activation gate.

The e.button !== 0 left-button gate plus the manual forward to dnd-kit's listeners?.onPointerDown?.(e) (after the spread handler is overridden) is non-obvious. A one-line note explaining that activation now happens on left-button pointer-down and is then handed to the sortable sensor would help future readers, especially given this reverts the prior pointer-up behavior.

📝 Suggested comment
+      // Why: activate immediately on left-button pointer-down (tab clicks must
+      // switch without waiting for pointer-up), then forward to dnd-kit so a
+      // drag can still start from the same gesture.
       onPointerDown={(e) => {
         if (e.button !== 0) {
           return
         }
         onActivate()
         listeners?.onPointerDown?.(e)
       }}
As per coding guidelines: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dff63c56-4ac2-4020-94bf-45912416956e

📥 Commits

Reviewing files that changed from the base of the PR and between a83e973 and aeee49205ea24d1ac93cf87a2d38da2898921143.

📒 Files selected for processing (11)
  • src/renderer/src/components/tab-bar/BrowserTab.test.tsx
  • src/renderer/src/components/tab-bar/BrowserTab.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.test.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.tsx
  • src/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsx
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/drop-indicator.test.ts
  • src/renderer/src/components/tab-bar/drop-indicator.ts
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsx
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
  • tests/e2e/tabs.spec.ts
💤 Files with no reviewable changes (4)
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsx
  • src/renderer/src/components/tab-bar/BrowserTab.test.tsx
  • src/renderer/src/components/tab-bar/drop-indicator.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/renderer/src/components/tab-group/tab-insertion.ts (1)

65-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a brief “why” comment for the single-edge normalization.

Returning only one edge here is the key contract change in this PR, and the interior-slot mapping to the next tab’s left edge is not obvious from the branch alone. A one-line rationale would make the behavior much easier to preserve during future drag/drop tweaks.

As per coding guidelines, "**/*.{ts,tsx,js,jsx}: When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Source: Coding guidelines

src/renderer/src/components/tab-group/tab-insertion.test.ts (1)

175-187: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a middle-slot right-edge regression case.

Please add an assertion for something like ['tab-1', 'tab-2', 'tab-3'] + { visibleTabId: 'tab-2', side: 'right' } → { visibleTabId: 'tab-3', side: 'left' }. That is the non-obvious branch introduced in resolveTabIndicatorEdges, and the shown tests only pin the simpler left-slot / terminal-right-slot shapes.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 58dfedfe-0b94-43b1-9682-f292f1823228

📥 Commits

Reviewing files that changed from the base of the PR and between aeee49205ea24d1ac93cf87a2d38da2898921143 and c569738.

📒 Files selected for processing (13)
  • src/renderer/src/components/tab-bar/BrowserTab.test.tsx
  • src/renderer/src/components/tab-bar/BrowserTab.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.test.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.tsx
  • src/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsx
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/drop-indicator.test.ts
  • src/renderer/src/components/tab-bar/drop-indicator.ts
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsx
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
  • src/renderer/src/components/tab-group/tab-insertion.test.ts
  • src/renderer/src/components/tab-group/tab-insertion.ts
  • tests/e2e/tabs.spec.ts
💤 Files with no reviewable changes (4)
  • src/renderer/src/components/tab-bar/BrowserTab.test.tsx
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsx
  • src/renderer/src/components/tab-bar/drop-indicator.test.ts
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/renderer/src/components/tab-bar/drop-indicator.ts
  • tests/e2e/tabs.spec.ts
  • src/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.test.tsx
  • src/renderer/src/components/tab-bar/BrowserTab.tsx
  • src/renderer/src/components/tab-bar/SortableTab.tsx

@Jinwoo-H
Jinwoo-H merged commit d32d62a into main Jun 26, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/fix-terminal-reorder-tab-switch branch June 26, 2026 01:36
nwparker added a commit that referenced this pull request Jul 3, 2026
* fix(tabs): restore deferred tab activation so dragging a terminal tab doesn't switch panes mid-gesture

PR #5927 shipped terminal-pane drag (reorder tabs, move a tab into another
pane, edge-split into a new column). It deliberately DEFERRED tab activation
to pointer-up and suppressed it during a drag, so pressing a tab to drag it
never switched the active tab or stole terminal focus mid-gesture.

PR #6395 (d32d62a) deleted tab-strip-pointer-activation.ts and made
SortableTab/EditorFileTab/BrowserTab activate eagerly on pointerdown — fixing
click-to-switch-after-reorder but regressing the drag: grabbing a tab now
flips the active tab + focused pane and yanks xterm keyboard focus before the
drag is even recognized (aggravated by PR #6210 raising the dnd-kit threshold
5px->12px). The move itself still lands, but the gesture feels broken.

Restore the deferred-activation hook, but gate it on measured pointer
DISPLACEMENT instead of the drag-active context ref the old hook used — that
ref clears asynchronously relative to the drop's pointerup, which is exactly
what made #6395's click-after-reorder misfire. Displacement mirrors dnd-kit's
own activation threshold: a release within TAB_DRAG_ACTIVATION_DISTANCE_PX is
a click (activate); crossing it is a drag (suppress). Because each press
measures its own gesture, a click after a reorder always activates.

- Recreate src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
  (displacement-gated) + unit tests, incl. an explicit #6395 regression case.
- Rewire onPointerDown in SortableTab, EditorFileTab, BrowserTab to use it.
- BrowserTab.test.tsx shallow-renders via mocked React hooks; add useRef/
  useCallback stubs so the new hook works under that harness.

Verified end-to-end in a dev build via CDP: pressing a tab no longer
activates/steals focus on pointerdown; a click still activates on release;
dragging a tab into another pane still moves it; clicking tabs after a drag
still switches (the #6395 guard in tests/e2e/tabs.spec.ts stays green because
it uses zero-displacement clicks). 233 unit tests pass; oxlint + renderer
typecheck clean.

* fix: restore pane detach tab placement
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(tabs): restore deferred tab activation so dragging a terminal tab doesn't switch panes mid-gesture

PR stablyai#5927 shipped terminal-pane drag (reorder tabs, move a tab into another
pane, edge-split into a new column). It deliberately DEFERRED tab activation
to pointer-up and suppressed it during a drag, so pressing a tab to drag it
never switched the active tab or stole terminal focus mid-gesture.

PR stablyai#6395 (04713f5) deleted tab-strip-pointer-activation.ts and made
SortableTab/EditorFileTab/BrowserTab activate eagerly on pointerdown — fixing
click-to-switch-after-reorder but regressing the drag: grabbing a tab now
flips the active tab + focused pane and yanks xterm keyboard focus before the
drag is even recognized (aggravated by PR stablyai#6210 raising the dnd-kit threshold
5px->12px). The move itself still lands, but the gesture feels broken.

Restore the deferred-activation hook, but gate it on measured pointer
DISPLACEMENT instead of the drag-active context ref the old hook used — that
ref clears asynchronously relative to the drop's pointerup, which is exactly
what made stablyai#6395's click-after-reorder misfire. Displacement mirrors dnd-kit's
own activation threshold: a release within TAB_DRAG_ACTIVATION_DISTANCE_PX is
a click (activate); crossing it is a drag (suppress). Because each press
measures its own gesture, a click after a reorder always activates.

- Recreate src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
  (displacement-gated) + unit tests, incl. an explicit stablyai#6395 regression case.
- Rewire onPointerDown in SortableTab, EditorFileTab, BrowserTab to use it.
- BrowserTab.test.tsx shallow-renders via mocked React hooks; add useRef/
  useCallback stubs so the new hook works under that harness.

Verified end-to-end in a dev build via CDP: pressing a tab no longer
activates/steals focus on pointerdown; a click still activates on release;
dragging a tab into another pane still moves it; clicking tabs after a drag
still switches (the stablyai#6395 guard in tests/e2e/tabs.spec.ts stays green because
it uses zero-displacement clicks). 233 unit tests pass; oxlint + renderer
typecheck clean.

* fix: restore pane detach tab placement
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