Repository navigation
fix(terminals): restore pane detach tab placement - #7215
Conversation
… 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.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (16)
📝 WalkthroughWalkthroughThe PR adds deferred tab activation on pointer-up via a new 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) 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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsx (1)
1-111: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winSolid coverage of the click/drag/cancel/regression matrix.
Good use of a real
renderHook/actharness with actualPointerEventdispatch rather than mocking React internals, and the regression test (Line 96) directly encodes the#6395bug this PR fixes.One gap: there's no test asserting that unmounting mid-gesture removes the
windowlisteners (theuseEffectcleanup at Line 38 of the hook). Given that's the leak-prevention path called out in the hook's own "Why" comment, a quick test would lock in that behavior.src/renderer/src/components/tab-bar/BrowserTab.tsx (1)
185-190: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRepeated unsafe cast for the forwarded dnd-kit listener.
listeners?.onPointerDown as ((event: React.PointerEvent<Element>) => void) | undefinedis duplicated verbatim acrossBrowserTab.tsx,EditorFileTab.tsx, andSortableTab.tsx. Since the hook already declaresdragListener?: (event: React.PointerEvent<Element>) => voidas its own parameter type, consider widening that parameter's type to accept whatever loose typeuseSortable().listenersactually returns (e.g.SyntheticListenerMap[string]), so callers can passlisteners?.onPointerDowndirectly without a cast at every call site.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: be77ff24-8d7e-4e9e-84a7-2ca4253da0cf
📒 Files selected for processing (6)
src/renderer/src/components/tab-bar/BrowserTab.test.tsxsrc/renderer/src/components/tab-bar/BrowserTab.tsxsrc/renderer/src/components/tab-bar/EditorFileTab.tsxsrc/renderer/src/components/tab-bar/SortableTab.tsxsrc/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsxsrc/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts
| const onPointerDown = useCallback( | ||
| (event: React.PointerEvent, dragListener?: (event: React.PointerEvent<Element>) => void) => { | ||
| if (disabled || event.button !== 0) { | ||
| return | ||
| } | ||
| // Why: start the dnd-kit gesture immediately on pointerdown; only the | ||
| // activation decision is deferred to release. | ||
| dragListener?.(event) | ||
|
|
||
| cleanupRef.current?.() | ||
| const startX = event.clientX | ||
| const startY = event.clientY | ||
| let draggedPastThreshold = false | ||
|
|
||
| const cleanup = (): void => { | ||
| window.removeEventListener('pointermove', onPointerMove) | ||
| window.removeEventListener('pointerup', onPointerUp) | ||
| window.removeEventListener('pointercancel', onPointerCancel) | ||
| cleanupRef.current = null | ||
| } | ||
| const onPointerMove = (moveEvent: PointerEvent): void => { | ||
| if ( | ||
| Math.hypot(moveEvent.clientX - startX, moveEvent.clientY - startY) >= | ||
| TAB_DRAG_ACTIVATION_DISTANCE_PX | ||
| ) { | ||
| draggedPastThreshold = true | ||
| } | ||
| } | ||
| const onPointerUp = (): void => { | ||
| const wasDrag = draggedPastThreshold | ||
| cleanup() | ||
| // Why: only a release that never crossed the drag threshold is a click. | ||
| // Activating after a real drag would yank the just-dropped tab's pane | ||
| // back to the source selection. | ||
| if (!wasDrag) { | ||
| onActivateRef.current() | ||
| } | ||
| } | ||
| const onPointerCancel = (): void => { | ||
| cleanup() | ||
| } | ||
|
|
||
| window.addEventListener('pointermove', onPointerMove) | ||
| window.addEventListener('pointerup', onPointerUp) | ||
| window.addEventListener('pointercancel', onPointerCancel) | ||
| cleanupRef.current = cleanup | ||
| }, | ||
| [disabled] | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
set -euo pipefail
printf '\n== outline ==\n'
ast-grep outline src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts --view expanded || true
printf '\n== target file lines ==\n'
cat -n src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts | sed -n '1,220p'
printf '\n== related searches ==\n'
rg -n "pointerId|isPrimary|tab-strip-pointer-activation|PointerSensor|pointermove|pointerup|pointercancel" src/renderer/src/components/tab-bar -SRepository: stablyai/orca
Length of output: 7472
🌐 Web query:
dnd-kit PointerSensor pointerId isPrimary source code activationConstraint pointerdown pointermove pointerup
💡 Result:
In the @dnd-kit/core library, the PointerSensor manages interaction via the browser's Pointer Events API. Its behavior is centered around the following mechanics: Primary Pointer Check The sensor only initiates a drag operation if the triggering event is the primary pointer [1][2]. Within the PointerSensor.ts source code, the onPointerDown activator explicitly checks the native event: if (!event.isPrimary || event.button!== 0) { return false; } This ensures that for touch or stylus input, only the first contact (the primary pointer) initiates the drag, and for mice, it restricts input to the primary button (button 0) [1][2]. Activation Constraints The PointerSensor uses activation constraints to control when a drag operation officially starts [2][3]. These are optional configurations applied to the sensor: 1. Distance Constraint: Requires the pointer to move a specific number of pixels before the drag starts [2][4]. 2. Delay Constraint: Requires the pointer to be held in place (or within a specific movement tolerance) for a set duration in milliseconds before the drag starts [2][4][3]. These constraints help distinguish between intentional drags and accidental inputs (like scrolling or quick taps) [2][3]. Event Lifecycle The sensor lifecycle is managed through standard pointer event handlers: onPointerDown: This is the entry point for the sensor [1][2]. It validates the pointer (using isPrimary) and, if valid, calls the onActivation callback to begin monitoring for drag activation constraints [1][5]. onPointerMove: The sensor tracks movement to determine if activation constraints (like distance) have been met or if an ongoing drag operation should be updated [6]. onPointerUp: This event (or pointercancel) typically cleans up the listeners and ends the drag interaction [7]. Source code indicates that the sensor attaches listeners to the document (via getOwnerDocument(event.target)) rather than individual elements to ensure that drag operations persist even if the target element is unmounted during the interaction [1]. Recent updates have also improved cleanup logic to use AbortController, ensuring that pending activation timers are correctly cancelled to prevent race conditions during rapid input sequences [7].
Citations:
- 1: https://github.com/clauderic/dnd-kit/blob/master/packages/core/src/sensors/pointer/PointerSensor.ts
- 2: https://github.com/dnd-kit/docs/blob/3cf8f8e6/api-documentation/sensors/pointer.md
- 3: https://dnd-kit.mintlify.app/extend/sensors/pointer-sensor
- 4: https://github.com/dnd-kit/docs/blob/master/api-documentation/sensors/pointer.md
- 5: https://github.com/clauderic/dnd-kit/blob/master/packages/core/src/sensors/pointer/AbstractPointerSensor.ts
- 6: https://clauderic-dnd-kit.mintlify.app/concepts/sensors
- 7: fix: abort activation controller on cleanup to prevent stale pointer capture clauderic/dnd-kit#1934
Scope the release listeners to the initiating pointer. window receives pointer events from every active contact, so a second touch/pen can flip draggedPastThreshold, cancel cleanup, or fire onActivateRef.current() for the wrong gesture. Capture event.pointerId on pointerdown and ignore move/up/cancel events from other pointers.
… shadow-cursor tracking Quality pass on terminal PRs merged 2026-07-03: - pane-split-close: extract a shared `teardownManagedPane` so `closeManagedPane` and `detachManagedPaneForExternalMove` can't drift apart on future edits (#7215). - terminal-link-activation: reuse the existing `isMacPlatform()` instead of a second inline `navigator.userAgent` copy, keeping one source of truth for Mac detection. - pty-connection: gate the shadow-cursor moves on empty CSI params so parameterized/ modified cursor keys (e.g. Ctrl+Left word-jump, `ESC[1;5D`) reset command tracking instead of silently desyncing the buffer used to infer a typed agent name; relocate the `getAuthoritativePaneAgent` JSDoc to the function it documents (#6954). No behavior change except the cursor-tracking hardening; all touched unit suites pass.
… shadow-cursor tracking (#7320) Quality pass on terminal PRs merged 2026-07-03: - pane-split-close: extract a shared `teardownManagedPane` so `closeManagedPane` and `detachManagedPaneForExternalMove` can't drift apart on future edits (#7215). - terminal-link-activation: reuse the existing `isMacPlatform()` instead of a second inline `navigator.userAgent` copy, keeping one source of truth for Mac detection. - pty-connection: gate the shadow-cursor moves on empty CSI params so parameterized/ modified cursor keys (e.g. Ctrl+Left word-jump, `ESC[1;5D`) reset command tracking instead of silently desyncing the buffer used to infer a typed agent name; relocate the `getAuthoritativePaneAgent` JSDoc to the function it documents (#6954). No behavior change except the cursor-tracking hardening; all touched unit suites pass.
* 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
… shadow-cursor tracking (stablyai#7320) Quality pass on terminal PRs merged 2026-07-03: - pane-split-close: extract a shared `teardownManagedPane` so `closeManagedPane` and `detachManagedPaneForExternalMove` can't drift apart on future edits (stablyai#7215). - terminal-link-activation: reuse the existing `isMacPlatform()` instead of a second inline `navigator.userAgent` copy, keeping one source of truth for Mac detection. - pty-connection: gate the shadow-cursor moves on empty CSI params so parameterized/ modified cursor keys (e.g. Ctrl+Left word-jump, `ESC[1;5D`) reset command tracking instead of silently desyncing the buffer used to infer a typed agent name; relocate the `getAuthoritativePaneAgent` JSDoc to the function it documents (stablyai#6954). No behavior change except the cursor-tracking hardening; all touched unit suites pass.
Summary
Verification
CI wait intentionally skipped per request.