Skip to content

fix(terminals): restore pane detach tab placement - #7215

Merged
nwparker merged 2 commits into
mainfrom
nwparker/Drag-terminal-into-a-tab-broken
Jul 3, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/Drag-terminal-into-a-tab-broken

Conversation

@nwparker

@nwparker nwparker commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • allow dragged terminal panes to drop at a selected tab-strip insertion point instead of always appending
  • preserve split leaf layout, PTY ownership, buffers, titles, and SSH/remote PTY ids when detaching a pane into a tab
  • add regressions for insertion placement, pane detach cleanup, layout leaf extraction, and primary-pane PTY ownership transfer

Verification

  • ./node_modules/.bin/vitest run --config config/vitest.config.ts src/renderer/src/lib/pane-manager/pane-split-close.test.ts src/renderer/src/components/terminal-pane/terminal-layout-leaf-detach.test.ts src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.test.ts src/renderer/src/lib/pane-manager/pane-drag-reorder.test.ts src/renderer/src/store/slices/store-cascades.test.ts
  • ./node_modules/.bin/tsgo --noEmit -p config/tsconfig.tc.web.json
  • oxlint/pre-commit on touched files
  • manual Electron proof: drag split pane header into tab strip, observe insertion marker, new tab lands before selected tab with PTY/layout ownership intact

CI wait intentionally skipped per request.

… 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.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9d289c14-090c-46d3-8083-67cabf126f6f

📥 Commits

Reviewing files that changed from the base of the PR and between a7a4a19 and 6245354.

📒 Files selected for processing (16)
  • src/renderer/src/assets/terminal.css
  • src/renderer/src/components/tab-group/TabGroupPanel.tsx
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/terminal-layout-leaf-detach.test.ts
  • src/renderer/src/components/terminal-pane/terminal-layout-leaf-detach.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/pane-drag-pointer.ts
  • src/renderer/src/lib/pane-manager/pane-drag-reorder.test.ts
  • src/renderer/src/lib/pane-manager/pane-drag-reorder.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
  • src/renderer/src/lib/pane-manager/pane-manager.ts
  • src/renderer/src/lib/pane-manager/pane-split-close.ts
  • src/renderer/src/store/slices/store-cascades.test.ts
  • src/renderer/src/store/slices/terminals.ts

📝 Walkthrough

Walkthrough

The PR adds deferred tab activation on pointer-up via a new useTabStripPointerActivation hook and updates tab components to use it. It also adds terminal-pane external drop support: pane-manager types and drag state now track external drop targets, terminal pane lifecycle passes external drop handlers through, and detach flows split terminal layouts, move panes into tabs, and sync PTY ownership. New tests cover the hook, layout detachment, tab detachment, and PTY reassignment.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and testing, but omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections, including cross-platform review and security audit details, and note 'No visual change' if applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: restoring deferred tab activation to fix tab-drag regressions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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

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.

❤️ 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.

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 win

Solid coverage of the click/drag/cancel/regression matrix.

Good use of a real renderHook/act harness with actual PointerEvent dispatch rather than mocking React internals, and the regression test (Line 96) directly encodes the #6395 bug this PR fixes.

One gap: there's no test asserting that unmounting mid-gesture removes the window listeners (the useEffect cleanup 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 win

Repeated unsafe cast for the forwarded dnd-kit listener.

listeners?.onPointerDown as ((event: React.PointerEvent<Element>) => void) | undefined is duplicated verbatim across BrowserTab.tsx, EditorFileTab.tsx, and SortableTab.tsx. Since the hook already declares dragListener?: (event: React.PointerEvent<Element>) => void as its own parameter type, consider widening that parameter's type to accept whatever loose type useSortable().listeners actually returns (e.g. SyntheticListenerMap[string]), so callers can pass listeners?.onPointerDown directly 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ff2c09 and a7a4a19.

📒 Files selected for processing (6)
  • src/renderer/src/components/tab-bar/BrowserTab.test.tsx
  • src/renderer/src/components/tab-bar/BrowserTab.tsx
  • src/renderer/src/components/tab-bar/EditorFileTab.tsx
  • src/renderer/src/components/tab-bar/SortableTab.tsx
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.test.tsx
  • src/renderer/src/components/tab-bar/tab-strip-pointer-activation.ts

Comment on lines +40 to +88
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]
)

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.

🎯 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 -S

Repository: 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:


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.

@nwparker nwparker changed the title fix(tabs): restore deferred tab activation for terminal-pane drag (regressed by #6395) fix(terminals): restore pane detach tab placement Jul 3, 2026
@nwparker
nwparker merged commit a84f737 into main Jul 3, 2026
3 checks passed
@nwparker
nwparker deleted the nwparker/Drag-terminal-into-a-tab-broken branch July 3, 2026 08:45
nwparker added a commit that referenced this pull request Jul 4, 2026
… 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.
nwparker added a commit that referenced this pull request Jul 4, 2026
… 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.
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
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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.
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