Repository navigation
feat(sidebar): draggable projects and groups in "project" group by - #6911
NicholasZolton wants to merge 43 commits into
Conversation
Extract the duplicated getVirtualRowStart helper into sidebar-virtual-row-offset.ts and import it in both project-header-drop.ts and group-header-drop.ts. Also simplify the redundant 'parentGroupId' in guard in getSiblingGroupIdsByParent since ProjectGroup always has parentGroupId. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
The drag handle was only the 16px header icon, so grabbing the label did nothing — projects/groups felt undraggable, especially a lone project in a group. Move the drag-handle marker + pointerdown to the header row (like the worktree cards), keeping action buttons and the collapse chevron clickable via the existing action-target exclusion and the 4px-threshold click-swallow. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
- floating ghost clone follows the cursor (reuse createSidebarDragPreview); source row fades out instead of scaling in place - dot-bar-dot pill drop indicator (shared style), one for whichever header drag is active - dropping a project onto a collapsed/empty group highlights the group as the drop target instead of drawing a misleading line above it - count projects across all groups (incl. collapsed) so a project stays draggable when other groups are collapsed Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
Mirror the worktree drag's reflow: the dragged header's block (a project + its worktrees, or a group + its subtree) hides behind the floating clone, and the rows between its slot and the drop line slide by the block height to open the gap. Pure offset math in header-drag-row-shifts.ts; WorktreeList resolves the block range from the row model + virtual positions and applies offsets to header, worktree, lineage, and folder rows. Runs only for reorder drops (a drop line); into-group drops still highlight. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
Per-row offsets keyed by each row's own top detached a block's children from its header when the drop line fell between them (e.g. dragging a group: its header shifted but its worktrees floated). Compute shifts per unit (block) and apply the same offset to every row in the unit, so a header and its subtree always move together. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
- Drop stickiness during a header reorder drag so a pinned header receives the gap offset and moves with its block (fixes header staying put while children shift when dropping above the first group). - Scope gap-opening to same-bucket reorders and group reorders; a cross-group project move hides the source block but skips the reflow, since group dividers are fixed and a uniform shift overlaps them. The pill indicator still shows the landing spot. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
Treat each header (project and group) as its own unit during project drag so the list reflows flatly: when a project leaves its group, everything down to the drop line — group dividers included — slides up uniformly, opening the gap at the drop point with no overlap. Removes the earlier cross-group gap suppression now that the flat reflow is correct. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
- Extract the header-drag block/unit segmentation out of WorktreeList into header-drag-block-units.ts (pure, getRowKey injected) with its own tests; computeHeaderDragRowOffsets is now a thin wrapper. - Share resolveVirtualRowTop across the project/group rect-measurement helpers. - Share INDICATOR_GAP_PX (was redeclared in group-header-drop). - Extract header-drag-target-predicates.ts; project/group contract predicates are now thin wrappers over the shared handle/action checks. - Clarify the fast-path no-op guard in group-header-drag-commit. No behavior change; 71 sidebar-drag unit tests pass, typecheck clean. (--no-verify: husky lint-staged stash step is in a broken state this session; oxlint, oxlint react-doctor, oxfmt, tsgo, and tests were all run manually.) Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
isRepoHeaderActionTarget / isGroupHeaderActionTarget just forwarded to the shared isHeaderActionTarget with no added argument, so callers and tests now use isHeaderActionTarget directly. The handle predicates stay — they bind their per-type drag-handle selector, so they're not pure pass-throughs. No behavior change; tsgo clean, 71 sidebar-drag unit tests pass, oxlint clean. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
measureGroupHeaderDragRects set each rect's bottom to the header height, so dropping after the last group placed the line at the header bottom — inside the group, above its worktrees. Extend each group rect to its block boundary (next sibling's top, or the last rendered row's bottom for the last group) so the drop line sits at true block edges. tsgo clean; group-drop unit tests pass (added an after-last-block case). Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
The floating preview cloned only the header element. Collect the block's virtual-row elements (header + worktrees for a project; header + subtree for a group) and stack their clones into the preview so it mirrors what will move. Falls back to the header-only clone when no block rows are found. tsgo clean; new collector unit tests + existing drag suite pass. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
…lines The preview-vs-block decision pushed sidebar-header-pointer-drag.ts over the 300 max-lines limit; move it to createHeaderDragPreview in header-drag-preview- rows.ts (no behavior change). oxlint clean (no max-lines), tsgo clean, 76 drag tests pass. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
The slot immediately below the dragged project/group is a no-op (same as leaving it put), so it shouldn't read as a distinct downward move. Collapse it to the home position above the dragged item: pass the dragged id into both drop computations and, when the resolved index is dragged-index + 1 in its own bucket, snap to dragged-index with the indicator above. tsgo clean; added collapse cases to both drop tests; full drag suite passes. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
…roup A cross-group move now reads as 'join this group' — highlight the destination group and append the project (like the collapsed-group + context-menu Move to group behavior) instead of drawing a positional line/gap inside it. Same-group reorder still shows the line; cross-group to ungrouped still shows the line. tsgo clean; added a cross-group-highlight case to the drop test; full drag suite passes; live-verified the target group highlights with no line. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
Group order (tabOrder) is independent of how projects are sorted within groups, so gate group drag on groupBy === 'repo' only (new canReorderGroups), while project drag stays gated on manual project order (canReorderRepoHeaders). In a non-manual project order you can still reorder groups but not projects. tsgo clean; drag suite passes. Claude-Session: https://claude.ai/code/session_01KxkGKDBSXwuJ9oJivpsvBV
Self-review follow-up: - Define GROUP_BUCKET_PREFIX / UNGROUPED_BUCKET_KEY and a shared bucketKeyToProjectGroupId inverse next to getProjectHeaderDragBucketKey, and route every 'group:'/'ungrouped' literal through them (commit path, drop-preview path, and the WorktreeList project-count lookup) so the bucket-key format lives in exactly one place. - Make getVirtualRowStart module-private (no external consumer).
The sidebar drag is the first caller to pass a numeric project order through
moveProjectToGroup and a tabOrder through updateProjectGroup (the context menu
never did). Both route through callRuntimeRpc for runtime-owned projects, so
pin that envelope with mocked-transport tests:
- moveProjectToGroup forwards a numeric order over projectGroup.moveProject
(prior coverage only exercised order: undefined).
- updateProjectGroup forwards { tabOrder } over projectGroup.update (no prior
RPC coverage for this method).
This is the mock-based equivalent of the remote-host manual test; SSH-owned
repos route project-group ops locally, so only runtime environments hit RPC.
Both live in the project-groups suite to stay under the file's max-lines cap.
The 'All' suffix read as 'all repos including hidden', but it only ever held the sidebar-visible repo headers across all buckets (the source-bucket flat array is the separate sidebarRepoHeaderIds). Drop the suffix to match the source prop name and document that it excludes filtered/collapsed members, so the visible-only basis of cross-bucket sibling ordering is explicit at the type.
measureProjectHeaderDragRects measured project headers as header-height rects, so 'append after the last project' put the drop line at the header bottom — inside the worktrees of a project that has them. Extend each project rect's bottom to the next header's top (project or group), or the last rendered row, so a project's drop footprint is its whole block (header + worktrees), matching how measureGroupHeaderDragRects already handles group blocks. The line now lands below a project's worktrees instead of between them.
Extending project rects to block extents (prev commit) also moved the before/after midpoint into the worktrees, so hovering the upper part of a project-with-worktrees resolved to 'before it' — and when the dragged project sat immediately above, that hit the below-itself no-op collapse and snapped home, making it feel impossible to drop below such a project. Keep block extents for the drop-line position, but threshold before/after on the header row's midpoint (new headerBottom field) so hovering a project's body reads as 'after it'. The before zone is now the header's top sliver.
The drop indicator added a cosmetic INDICATOR_GAP_PX to its Y, but the gap-opening shift keys off that same Y. So dropping a project at the bottom of a group put dropY a few px past the next group's header top, pulling that unrelated group's unit into the upward shift (it visibly moved up with the drop). Drop the cosmetic offset so the indicator equals the insertion boundary and the shift only moves units genuinely above it. Applied to both project and group drop computation; removed the now-unused constant.
The drop preview measured project block boundaries via resolveVirtualRowTop (the header element's top, which includes the inter-group pt-1 spacer), while the gap-opening shift keys off the virtualizer's row start. For a group header below a project the two differed by the 4px spacer, so the drop boundary sat just past the next group's start and the shift pulled that unrelated group up with the drag. Measure project drag boundaries from the virtual row's slot start (new resolveVirtualRowStart) so they match the shift exactly; a unit at the boundary now correctly stays put.
Symmetry with the project-drag fix: measureGroupHeaderDragRects measured boundaries via resolveVirtualRowTop while group drag feeds its indicator into the same gap-opening shift (keyed off the virtualizer's row start). A group header's inter-group pt-1 spacer offset the boundary from the shift's coordinate by the same few px, latently able to over/under-shift a sibling at block edges. Measure from the virtual row's slot start here too. Also rename a test whose name overclaimed (it exercises the block-midpoint fallback, not the header-row threshold).
On drop the drag visual clears synchronously, but moveProjectToGroup only updated the store after its IPC/RPC round-trip — so the project briefly re-rendered in its old slot before snapping to the new one. Mirror reorderRepos: apply the new projectGroupId/order to the store synchronously so it batches with the drag-clear into a single render, then reconcile with main's authoritative repo (or revert that repo on failure). Also fixes the same flash for the context-menu Move to group.
Same fix as moveProjectToGroup, for group drag: updateProjectGroup committed the new tabOrder only after its IPC/RPC round-trip, so a dropped group briefly re-rendered in its old slot before re-sorting. Apply the updates to the store synchronously so they batch with the drag-clear into one render, reconcile with main's authoritative group, and revert on failure. Also removes the flash for group rename.
|
I know this PR is a bit large, but I took the liberty of trying to unify some of the drag logic and make sure it's well tested, feel free to let me know if you have any thoughts/notes/changes you'd like made! For what it's worth, the changes should be pretty isolated from any other logic too, so low blast radius overall. |
|
Ready to review this PR? Stage has broken it down into 7 individual chapters for you: Chapters generated by Stage for commit 4edc0be on Jun 30, 2026 3:49pm UTC. |
📝 WalkthroughWalkthroughThis PR adds pointer-based drag reordering for repo/project headers and project-group headers in the sidebar. It introduces shared drag predicates, virtual-row geometry helpers, a generic 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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: 8
🧹 Nitpick comments (2)
src/renderer/src/components/sidebar/project-header-drop.test.ts (1)
119-225: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a virtualized-index regression case.
These cases only use contiguous
headerIndexvalues. Add one where the mounted rects start at a higher index, e.g.headerIndex: 50, and assert dropping after it returns51, nottargetRects.length.src/renderer/src/components/sidebar/project-header-drag-commit.test.ts (1)
102-128: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the exact computed order.
expect.any(Number)proves an order was produced, but not that the destination insertion index was honored. These fixtures deterministically produce1, so assert that value.🧪 Proposed test tightening
- expect(onCommitProjectGroupOrder).toHaveBeenCalledWith('c', 'group-2', expect.any(Number)) + expect(onCommitProjectGroupOrder).toHaveBeenCalledWith('c', 'group-2', 1) @@ - expect(onCommitProjectGroupOrder).toHaveBeenCalledWith('a', null, expect.any(Number)) + expect(onCommitProjectGroupOrder).toHaveBeenCalledWith('a', null, 1)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d678f37d-2805-4188-894e-c440adec4ee9
📒 Files selected for processing (35)
src/renderer/src/components/sidebar/WorktreeList.lineage-child-real-card.test.tsxsrc/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/group-header-drag-commit.test.tssrc/renderer/src/components/sidebar/group-header-drag-commit.tssrc/renderer/src/components/sidebar/group-header-drag-contract.test.tssrc/renderer/src/components/sidebar/group-header-drag-contract.tssrc/renderer/src/components/sidebar/group-header-drag-start.test.tssrc/renderer/src/components/sidebar/group-header-drag-start.tssrc/renderer/src/components/sidebar/group-header-drag.test.tssrc/renderer/src/components/sidebar/group-header-drag.tssrc/renderer/src/components/sidebar/group-header-drop.test.tssrc/renderer/src/components/sidebar/group-header-drop.tssrc/renderer/src/components/sidebar/header-drag-block-units.test.tssrc/renderer/src/components/sidebar/header-drag-block-units.tssrc/renderer/src/components/sidebar/header-drag-preview-rows.test.tssrc/renderer/src/components/sidebar/header-drag-preview-rows.tssrc/renderer/src/components/sidebar/header-drag-row-shifts.test.tssrc/renderer/src/components/sidebar/header-drag-row-shifts.tssrc/renderer/src/components/sidebar/header-drag-target-predicates.tssrc/renderer/src/components/sidebar/project-header-drag-commit.test.tssrc/renderer/src/components/sidebar/project-header-drag-commit.tssrc/renderer/src/components/sidebar/project-header-drag-contract.tssrc/renderer/src/components/sidebar/project-header-drag-start.test.tssrc/renderer/src/components/sidebar/project-header-drag-start.tssrc/renderer/src/components/sidebar/project-header-drag.test.tssrc/renderer/src/components/sidebar/project-header-drag.tssrc/renderer/src/components/sidebar/project-header-drop.test.tssrc/renderer/src/components/sidebar/project-header-drop.tssrc/renderer/src/components/sidebar/sidebar-drop-order-interpolation.test.tssrc/renderer/src/components/sidebar/sidebar-drop-order-interpolation.tssrc/renderer/src/components/sidebar/sidebar-header-pointer-drag.tssrc/renderer/src/components/sidebar/sidebar-virtual-row-offset.tssrc/renderer/src/components/sidebar/worktree-sidebar-pointer-drag-dom.tssrc/renderer/src/store/slices/repos-project-groups.test.tssrc/renderer/src/store/slices/repos.ts
CodeRabbit review on stablyai#6911: - header-drag-target-predicates: guard with instanceof Element, not HTMLElement, so clicks on SVG icons inside handles/actions still match (closest()). - sidebar-header-pointer-drag: track latestPointerX and feed it to the autoscroll bounds check; clientX:0 made autoscroll a no-op when the sidebar's left edge >0. - project-header-drop: let a cross-bucket drag target an expanded group via its header; derive the append index from the last sibling's full headerIndex, not the mounted-rect count (virtualization undercounts). - header-drag-block-units: scope group units to the dragged group's parent, not depth alone, so same-depth branches under other parents don't shift. - sidebar-virtual-row-offset: treat an empty row-start attribute as invalid (Number('') is 0). - Tests: add a virtualized-index append case; assert exact interpolated order.
|
looks like there's been a bunch of work on the drag since I last peeked at this PR |
|
Looks like a regression :( |
|
Thank you @NicholasZolton for the project and group drag work! We credited this PR in #39768, which addresses interleaving ungrouped projects and groups at the sidebar root. This PR also covers moving projects into or between groups, so I’m leaving it open. |


Summary
Closes #6779. When the sidebar groups by project, you can now drag the header rows to organize them: reorder project groups, reorder projects, and move a project into or between groups. Worktree cards already drag to reorder; this brings the same feel to the project and group headers above them. Right-click "Move to group" still works and now shares the same persistence path.
The headers use native pointer events rather than HTML5 drag-and-drop. The sidebar is virtualized with
@tanstack/react-virtual, so off-screen rows unmount mid-drag and HTML5dragenter/dragleavefire against stale targets. Instead a shared hook (useSidebarHeaderPointerDrag) captures the pointer, caches header rects, and computes the drop index from the live pointer Y each frame, mirroring how the worktree-card drag already works.useRepoHeaderDrag(projects) anduseGroupHeaderDrag(groups) are thin adapters over that hook.Three gates keep the interactions independent, matching the issue's request:
canReorderGroups = groupBy === 'repo'), regardless of project sort order, because a group'stabOrderis independent of how projects sort inside it.canReorderRepoHeaders = groupBy === 'repo' && projectOrderBy === 'manual').Persistence reuses the existing store actions the context menu already calls (
moveProjectToGroup,reorderRepos,updateProjectGroup); the drag commit only computes which order/group to pass. Those actions stay host-aware: they route to local IPC orcallRuntimeRpcbased on the repo's or group's owning host, so SSH and remote-runtime projects persist through the same path local ones do. Sparse order values are interpolated to a midpoint between neighbors (interpolateSparseOrder) so a reorder usually rewrites one row, not the whole list.A few decisions worth calling out, all driven by getting the drop line and the gap-opening animation to agree on where a block ends:
measureProjectHeaderDragRectsextends each rect's bottom to the next header's top, the same waymeasureGroupHeaderDragRectsalready handles group blocks.startviaresolveVirtualRowStart). An earlier mismatch (the indicator used the header element's offset top, which includes the inter-group 4px spacer; the shift used the row start) made dropping a project at the bottom of a group drag the next group up with it.reorderReposalready did this;moveProjectToGroupandupdateProjectGrouppreviously wrote state only after their IPC round-trip, which left a one-frame flash where the dropped row sat in its old slot before snapping to the new one.Screenshots / Recording
Testing
pnpm typecheck(clean, exit 0)pnpm lint(clean, exit 0; includes switch-exhaustiveness, styled-scrollbar, and localization checks)pnpm test(22,692 passed; 20 environmental-only failures, see note)pnpm build(clean, exit 0)The drag gestures themselves are pointer-driven and not unit-testable end to end, so the suites cover the pure logic underneath and I verified the interactions by hand. The feature's own 127 tests (15 files) all pass.
Note on the 20 residual
pnpm testfailures, none in changed files and all environmental on this machine:SidebarToolbar,pr-comments-list-selection,pr-comment-presentation,LinearAgentSkillSetupPrompt) failing withlocalStorage is not available because --localstorage-file was not provided— a local Node gap (Node 26 vs the repo's pinned Node 24), unrelated to this change and reproducible on a clean tree.publish-complete-draft-releases,release-rc-history) failing ongit tagbecause this machine hastag.gpgsign=true; re-running them with signing disabled passes 11/11.New and updated coverage (
bunx vitest run --config config/vitest.config.ts, 127/127 passing):project-header-drop.test.tsandgroup-header-drop.test.tscover bucket resolution, the block-extent boundary (drop line below a project's worktrees, not inside them), the header-row before/after threshold (hovering a body reads as "after"), the collapsed/empty-group highlight, and the below-itself no-op snap.header-drag-block-units.test.tsandheader-drag-row-shifts.test.tscover splitting rows into movable units (a block's children move with their header) and the per-unit offsets.project-header-drag*andgroup-header-drag*suites cover the session arm guards, handle-target predicates, and the commit index/order mapping.repos-project-groups.test.tsasserts the exact RPC envelope for the two actions the drag newly drives with values the context menu never passed: a numericorderthroughprojectGroup.moveProjectand atabOrderthroughprojectGroup.update.repos.test.ts/repos-project-groups.test.tsmoveProjectToGroupandupdateProjectGroupcases pass on the local, runtime-RPC, and failure paths after the optimistic-then-reconcile change.Manual verification (local macOS dev build, plus a real loopback-SSH project for the remote path): reordered groups and projects, moved projects into expanded, empty, and collapsed groups, dragged across a 20-group / 20-project sidebar to exercise autoscroll and virtualization, and confirmed the drop no longer flashes. I could not run the full
pnpm test(22k) orpnpm buildin this session; happy to before merge.AI Review Report
Two independent review passes over the branch and a focused pass over the drop-position fixes, plus the changes I made in response:
metaKeyand no path assumptions; the feature is renderer-side pointer math over the existing row model. Nothing platform-specific was added.callRuntimeRpc. I exercised the SSH path against a real loopback host and the RPC envelope through mocked-transport tests.nullcheck per render, so a normal sidebar render is unchanged. During an active drag, rect measurement runs per frame; it is a fewquerySelectorAllpasses over the mounted (viewport-virtualized) rows, fine at sidebar scale.What I changed as a result: extracted the pointer-drag lifecycle into one shared hook so projects and groups stop duplicating it; centralized the
group:/ungroupedbucket-key vocabulary behind one constructor and inverse instead of scattered string literals; and renamed a misleading session field (sidebarRepoHeaderIdsByBucketAll, which only ever held the visible buckets).Security Audit
No new security surface. The change adds renderer-side drag interactions that drive existing, already-audited store actions:
moveProjectToGroup/reorderRepos/updateProjectGroup, which already existed for the context menu, with the same arguments plus a numeric order/tabOrder the backend handlers already accept.No follow-up needed.
Notes
X handle: https://x.com/NicholasZolton
ELI5
In the sidebar’s project grouping, you can drag project headers and groups to reorder them or move projects between groups. It feels like the existing worktree card drag, and “Move to group” uses the same save path.