Repository navigation
Fix tab switching after terminal tab reorder - #6395
Conversation
Co-authored-by: Orca <[email protected]>
aeee492 to
c569738
Compare
📝 WalkthroughWalkthroughThe tab bar components remove the pointer-activation hook and selection-chrome helper, change tab root styling to depend on 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/tab-bar/BrowserTab.tsx (1)
180-186: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a short "why" comment for the pointer-down activation gate.
The
e.button !== 0left-button gate plus the manual forward to dnd-kit'slisteners?.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.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."📝 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) }}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.tsxsrc/renderer/src/components/tab-bar/BrowserTab.tsxsrc/renderer/src/components/tab-bar/EditorFileTab.test.tsxsrc/renderer/src/components/tab-bar/EditorFileTab.tsxsrc/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsxsrc/renderer/src/components/tab-bar/SortableTab.tsxsrc/renderer/src/components/tab-bar/drop-indicator.test.tssrc/renderer/src/components/tab-bar/drop-indicator.tssrc/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsxsrc/renderer/src/components/tab-bar/tab-strip-pointer-activation.tstests/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
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/renderer/src/components/tab-group/tab-insertion.ts (1)
65-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd 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 winAdd 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 inresolveTabIndicatorEdges, 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.tsxsrc/renderer/src/components/tab-bar/BrowserTab.tsxsrc/renderer/src/components/tab-bar/EditorFileTab.test.tsxsrc/renderer/src/components/tab-bar/EditorFileTab.tsxsrc/renderer/src/components/tab-bar/SortableTab.rename-shortcut.test.tsxsrc/renderer/src/components/tab-bar/SortableTab.tsxsrc/renderer/src/components/tab-bar/drop-indicator.test.tssrc/renderer/src/components/tab-bar/drop-indicator.tssrc/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsxsrc/renderer/src/components/tab-bar/tab-strip-pointer-activation.tssrc/renderer/src/components/tab-group/tab-insertion.test.tssrc/renderer/src/components/tab-group/tab-insertion.tstests/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
* 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
Co-authored-by: Orca <[email protected]>
* 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
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.tspnpm 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.tspnpm run typecheck:webpnpm 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=1Made with Orca 🐋