Skip to content

Highlight the whole section on sidebar thread drops - #4010

Merged
ymichael merged 14 commits into
mainfrom
bb/improve-sidebar-drag-and-drop-logic-thr_t9ke9t6qb8
Sep 21, 2026
Merged

ymichael merged 14 commits into
mainfrom
bb/improve-sidebar-drag-and-drop-logic-thr_t9ke9t6qb8

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The sidebar previewed a cross-section thread drop by projecting the comparator, inserting a full-height ghost row at the projected index, and pulling the dragged row out of flow. Both the source and destination lists reflowed on every pointer move, and that reflow fed back into dnd-kit's collision detection — which is why the code needed a projection gate, retained rects and fallback row rects to stay stable (#1830). Only the pinned section can actually be ordered by hand, so for every other section the projected index was a guess the user could not act on.

What changed

Frozen layout for the whole drag. The destination container now highlights as a single overlay above its sticky header — top-level sections, projects, machine sections, Pinned and Threads — driven by the already-resolved dragOverParentKey. An insertion line renders only where the position is real (the pinned insert/reorder pseudo-element), anchored to the subtree boundary rather than the row, since buildPinInsertRequest lands the thread after the parent's entire subtree. The dragged row stays in flow, dimmed, so its section keeps its shape. With nothing inserted or removed, the projection machinery goes away: sidebarDropPreviewPlacement, useRenderedSectionThreadDnd, SectionThreadProjectionGate and its document input tracking, and the initial-row-rect fallback.

No-op targets are acknowledged rather than dead. A thread over its own section, a loose thread over Threads, and a pinned root over the Pinned header now resolve to an unchanged decision and render the overlay in a neutral tone, instead of returning null and leaving the container with no treatment. Drops still do nothing. Section reorder keeps its own tint, fed only while no thread is being dragged, so the two treatments can no longer stack.

The re-parent drop UI is unchanged from main. An earlier revision of this branch replaced the nest target's fill and ring with an underline at the child indent; that is reverted. ThreadRow is identical to main apart from exporting REORDER_PLACEMENT_CLASS, and the ghost child row is back, projected the way main projected it — patch the dragged thread onto the parent, rebuild through buildPinnedSidebarState/buildSectionThreadList, read off the sibling it sorts ahead of — but only for the nest case (sidebarNestPreviewPlacement.ts, useNestDropPreview.ts). The parent's subtree is the only list that moves during a drag.

One deliberate deviation from main: the dragged row stays dimmed in place rather than being pulled out of flow, so during a nest hover the thread appears twice — dimmed at its origin, and as the ghost under the target. Restoring main's disappearing source row would reintroduce the dual-list reflow this PR removes.

Merged with main at 3f74c55: groupThreadsByEnvironment is threaded into the nest-only projection from the same atom useRenderedSectionThreadDnd read, the dimmed source row keys off main's activeItemId, and dropParentKey moves onto main's MachineSidebarSection.

How you verified

pnpm exec turbo run typecheck lint --filter=@bb/app — clean, 0 lint errors. pnpm exec turbo run test --filter=@bb/app — 558 files, 5090 passed.

New tests: sidebarNestPreviewPlacement.test.ts covers the projected child position (ahead of the sibling it sorts before, end of list, childless parent, pinned parent); ProjectRow.interactions.test.tsx covers the ghost row's position among existing children, its absence on a blocked target, and the pinned insert line anchoring below the subtree rather than between parent and first child.

Manual, driving real drags in the dev app: hovering a leaf arms main's fill and ring with the ghost indented beneath it; hovering a parent with children places the ghost at the projected index among them rather than at the end; a blocked target draws the destructive ring with no ghost; dropping reparents the thread in the database to exactly where the ghost sat, with no leftover preview or overlay nodes; dragging over a section shows the whole-section overlay with no nest preview; hovering the section a thread already sits in shows the neutral overlay and leaves the database untouched.

Known difference worth a reviewer's eye. Comparing the same synthetic drags against a pristine origin/main build, main arms a nest target while the pointer is held completely still, and this branch needs a further hair of pointer movement before it arms. The cause looks inherent to freezing the layout: on main the drag keeps changing the DOM, so dnd-kit keeps recomputing collisions while the pointer rests; here nothing moves, so the 350 ms hover dwell only converts into an armed target on the next pointer event. With continuous pointer motion both builds arm identically, and a real mouse or trackpad rarely goes fully silent — but it is a behaviour change, it predates the re-parent revert above, and restoring main's initial-row-rect fallback did not close it.

Fixes #

AGENT GENERATED

ymichael and others added 14 commits September 16, 2026 13:41
The sidebar previewed a cross-section drop by projecting the comparator,
then inserting a full-height ghost row at the projected index and pulling
the dragged row out of flow. Both the source and destination lists
reflowed on every pointer move, and the reflow fed back into dnd-kit's
collision detection, which needed a projection gate, retained rects and
fallback row rects to stay stable (#1830).

Only the pinned section can actually be ordered by hand, so for every
other section that projected index was a guess the user could not act on.

Freeze the layout for the whole drag instead:

- The destination container highlights as a whole - header and rows,
  top-level sections, projects, machine sections, Pinned and Threads -
  from the already-resolved dragOverParentKey.
- An insertion line only renders where the position is real: the
  existing zero-layout pseudo-element for pinned insert/reorder.
- A nest target keeps its existing row ring; no ghost child row.
- The dragged row stays in flow, dimmed, so its section keeps its shape.

With nothing inserted or removed, the projection machinery that existed
to survive the reflow goes away: the drop-preview placement projection,
the rendered-dnd wrapper hook, SectionThreadProjectionGate and its
document input tracking, and the initial-row-rect fallback.

Verified by driving real drags in the dev app: dropping across sections
highlights the destination with no row movement, dropping into Pinned
shows the insertion line, and hovering a row still arms nesting.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Follow-up on the section-highlight prototype, from feedback on how the
states read while dragging.

The section highlight was two tinted surfaces: the group, plus the sticky
header, which is opaque and paints over the group. That double tint made
the header a visibly different shade from the rows, so the highlight read
as a header and a body rather than one section. Replace both with a
single overlay element, positioned above the sticky header, so the
section highlights as one continuous surface.

Parenting drew a ring around the whole target row, which read the same as
the other row states. Underline the parent instead, starting at the
indent where the new child's content will begin, so the line points at
where the thread lands. The ring is gone; a valid target keeps the accent
tint to identify the row.

A drop into Pinned showed the insertion line and the section highlight at
the same time, which is two answers to one question. Suppress the section
highlight whenever a reorder target is set: an explicit position always
wins over the containing section. Nesting already did this.

Verified by dragging in the dev app: the section highlight is continuous
across header and rows, a nest target underlines the parent with no
section highlight, and a pinned insert shows only the line.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Dropping onto the lower half of a pinned thread that has children drew
the insertion line at the bottom edge of that row, which put it between
the parent and its first child. It read as "insert here as the first
child", which is not what happens: the pinned list is ordered by roots,
so buildPinInsertRequest lands the thread after the parent's entire
subtree, below the last child.

Draw the line at the subtree boundary instead. "before" already sat at
the top of the row, which is the top of the subtree. "after" now renders
on the group that wraps the row and its children, so it lands below the
last child. A collapsed parent renders no children, so its group ends at
the row and the line stays there.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The section drop overlay is z-70, but useSidebarSortable lifted every
dragged row to z-100. Both call sites that dim the dragged row spread
that style and override only opacity, so the z-index survived. When the
highlighted section contained the dragged row - drag a pinned child
while hovering inside Pinned - the row painted above the tint and read
as a notch in a highlight that is meant to be one continuous surface.

The lift exists so a row being dragged with displacement floats over the
siblings it slides past. A row rendered with displace: false never moves,
so it has nothing to float over. Tie the lift to displace instead of to
isDragging; opacity still tracks isDragging, and the positioned row class
already anchors the drop indicators, so nothing else depends on the
inline position.

Verified in the dev app: dragging a pinned child inside Pinned tints the
header and every row evenly, with the dragged row dimmed in place and no
break in the surface. Measured in the DOM, the dragged row drops from
z-100 to z-auto under the z-70 overlay, with no stacking context between
them.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Every container highlighted on hover except one: the section the dragged
thread already belongs to. Dropping there changes nothing, so
resolveSectionThreadDropDecision returned null, which left
dragOverParentKey null and the section with no treatment at all. Against
the new full-section highlight that dead spot reads as a broken
dropzone rather than a no-op.

Report the no-op instead of dropping it. A same-container hover now
resolves to an "unchanged" decision carrying the container it names, and
the section renders the drop overlay in a neutral tone - the ring
without the accent fill. This is the vocabulary the sidebar already uses
for a nest target that would not move the thread, so every no-op target
now reads the same way: acknowledged, and visibly not a change. Drops
still do nothing.

The three container no-ops share the path: a thread over its own
section, a loose thread over Threads, and a pinned root over the Pinned
header. A row-level target still wins, so arming a nest or a pinned
insert replaces the section treatment as before.

Verified in the dev app across all three, and that dropping on the
thread's own section leaves the database untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A section carried two drop treatments at once. The overlay is one, and
the group still tinted itself with bg-sidebar-accent/60 whenever
sortable.isOver was set - which dnd-kit also sets while a thread is
dragged over the section, not just while sections are being reordered.

That tint sits under the sticky header, which is opaque, so it painted
on the rows and not on the header. The accent overlay is opaque enough
to hide the split, which is why it only surfaced once the muted state
landed with no fill: the section read as a tinted body under an
untinted header.

Feed isDropTargetActive only while no thread is being dragged. Section
reorder keeps its tint, thread drops are the overlay's alone, and the
two can no longer stack.

With the section reading as one surface again, give the muted state a
fill of its own - a quarter of the accent against the active state's
45%, with a neutral ring rather than the accent one. It reads as a
state rather than an absence, and stays clearly below a real target.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Six treatments for the nest target on the same row, side by side, so
the choice can be made by looking rather than by rebuilding the app:
the current underline, a tree elbow, a short dash at the child indent,
an outline with no fill, an explicit ghost child row, and a leading bar.

Story only - production behaviour is untouched. Two earlier candidates
were dropped after rendering them: a vertical bar at the child indent
and a fill starting at the child indent both cut through the parent's
title, because at these depths the child indent lands inside the row's
text rather than in a gutter.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comparing the candidates against each other says nothing about whether
the branch improved on what shipped. Add G, reproduced from main rather
than from memory: the filled row with a ring around it
(NEST_TARGET_STATE_CLASS.valid before the branch), the ghost child row
carrying the dragged thread's title at 50% opacity, and the source row
pulled out of flow so it vanishes from its own list.

That last part is the half that is easy to forget when only the target
row is compared: on main the drag removed a row and added another, so
two lists moved at once.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Filled row with main's ring restored, plus the branch's underline from
the child indent, and the source row left dimmed in place.

Rendered literally the two marks cancel: the underline is 2px at the
row's bottom edge and the ring is 1px inset on that same edge, both
sidebar-ring, so the underline disappears into the ring and the row
reads as plain G. H2 lifts it 3px so it sits inside the ring and reads
as its own mark.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
H put a 2px rule on the same pixels as the ring's 1px inset edge, so
one hid the other. Hang the rule directly below that edge instead: the
two are contiguous, and from the child indent rightwards the ring simply
reads thicker - 3px where the child lands, 1px everywhere else. No
second mark competing with the selection, and the indent still reads.

H3 is 2px, which exactly fills the 2px gap between rows, so the rule
stops where the child row begins. H4 is the 3px version for comparison;
it crosses a pixel into the row below.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
H3's rule ran to 2px from the row's right edge, but the ring's bottom
edge stops turning 6px earlier, so the rule carried on past the curve
and ended in a rounded cap hanging off the corner.

H3b just ends the rule 6px early, at the tangent. It no longer overhangs
but it now stops short of the corner with a visible gap, which reads as
a stub rather than as a thicker edge.

H5 clips the rule to the row's rounded bottom instead, at the concentric
outer radius for a 2px offset. The thickening turns the corner with the
ring and tapers out where the ring's curve begins, so the two read as
one edge that is simply heavier from the child indent rightwards.

Compared at 6x magnification on the bottom-right corner of each.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The nest target was a filled row with a rule along its bottom edge, the
same 2px accent rule the pinned insert line uses, differing only by a
24px left inset. Two opposite outcomes - become a child, or land as a
sibling - rendered as nearly the same mark.

Outline the target row again and hang the rule directly below that
outline instead of on the row. The two are contiguous, so from the
child indent rightwards the row's edge simply reads thicker, and the
mark is an asymmetry in the selection rather than a second line that
can be mistaken for an insert. The rule stops 6px early, at the radius,
so it ends where the outline starts to turn instead of running past the
corner.

Applied to all three states, tone being the only difference: accent for
a valid parent, destructive for a blocked one, border for a drop that
changes nothing. Blocked and unchanged had lost their outlines earlier
in the branch and get them back here.

Verified on real drags: geometry holds on leaf and sticky parent rows
alike - rule flush under the outline, starting at the child indent,
ending at the radius - and no ancestor clips the 2px that now sits
outside the row box.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The branch replaced the nest target's fill and ring with an underline at
the child indent, then spent five commits tuning where that line sits
relative to the ring. The section overlay work is the part worth
shipping; the nest redesign is not, so put the shipped treatment back and
keep the frozen layout underneath it.

ThreadRow returns to main exactly: fill and ring for a valid target,
destructive ring for a blocked one, border ring for a no-op, and nest and
reorder classes applied together rather than one shadowing the other.
The underline and its offset constants are gone, as is the Ladle story
that compared the six candidates.

The ghost child row comes back with it. It is the half of main's answer
that says where the thread lands, and without it the target row says only
that something will happen. Its position is projected the way main
projected it - patch the dragged thread onto the parent, rebuild through
buildPinnedSidebarState or buildSectionThreadList, and read off the
sibling it sorts ahead of - but only for the nest case, so the container
and pinned projections the branch deleted stay deleted along with the
gate and retained rects they needed. The parent's subtree is the only
list that moves during a nest hover.

Everything else the branch does is untouched: cross-section drops still
highlight the whole destination with no row movement, pinned inserts
still draw the line at the subtree boundary, no-op containers still read
as acknowledged, and the dragged row still stays dimmed in place. That
last one is a deliberate deviation from main, which pulled the source row
out of flow - during a nest hover the thread now shows twice, once dimmed
at its origin and once as the ghost.

Verified by driving real drags in the dev app: hovering a leaf arms the
fill and ring with the ghost indented beneath it, hovering a parent with
children places the ghost at the projected index among them rather than
at the end, a blocked target draws the destructive ring with no ghost,
dropping reparents the thread to exactly where the ghost sat, and
dragging over a section still shows the overlay with no nest preview.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The branch deleted sidebarDropPreviewPlacement, useRenderedSectionThreadDnd
and the projection gate; main meanwhile threaded groupThreadsByEnvironment
through the projection, added activeItemId for worktree-group drags, and
rewrote MachineModeSections around ThreadListVisibility.

Keep the deletions, and port what main added to the paths that survive:
the nest-only projection now takes groupThreadsByEnvironment from the same
atom useRenderedSectionThreadDnd read, the dimmed source row keys off
activeItemId rather than the active thread's id, and the section overlay's
dropParentKey moves onto main's MachineSidebarSection.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ymichael
ymichael merged commit d72bda3 into main Sep 21, 2026
16 checks passed
@ymichael
ymichael deleted the bb/improve-sidebar-drag-and-drop-logic-thr_t9ke9t6qb8 branch September 21, 2026 20:40
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