Repository navigation
Description
Part of #499. Read the parent first. Step 3. Can run beside #501 and #502. Work on main.
Summary
- Today. The TOC picks the drop row by the nearest row centre, then rewrites the gap with two normalisers. A drop on the lower half of a folded row lands inside the fold (measured). A drop on the lower half of the Title row sends the section to the end of the document (measured).
- After. One rect-based zone model picks the row under the pointer. Every gap has one name and paints one line. Folded rows, the Title row, the header row and the dragged set each get a fixed rule.
- Not here. The level rule, the sideways offset and the drop-line indent stay as they are. Set the drag level from the row above and indent the drop line #504 changes them.
This is a bug fix. It adds no token, recipe or motion. One stock cursor value (no-drop over the header row) needs a maintainer ruling; see Decision A.
Maintainer rulings that bind this issue
The full text is on #499.
- R2. A level change is a level change; the section logic derives the tree. So the hit test never blocks a gap because a drop there would capture headings.
- R3. The first H1 is the Title. Nothing drops above it, so the Title row has no before zone.
- R4. Never block a move because of depth. The hit test never reads the children of a row to refuse a gap.
- R5. Drop ON a heading puts it inside. This issue adds no inside zone. Drop a section onto a TOC heading to put it inside #508 adds the middle band to the zone model built here.
- R6. A set is one heading plus its whole subtree. The rows of the set are never targets.
Depends on / Blocks
- Depends on Move a TOC section with its sub-headings and keep the Title fixed #500. The gaps next to the set name the source's own slot. Only the planner turns that into a no-op instead of an empty delete plus insert. The planner also refuses any insert above the Title, which is the last net behind the zone rule here.
- After Move a TOC section with its sub-headings and keep the Title fixed #500,
moveHeadingSectionis a thin wrapper. It callsplanMovewith{ position, targetId, level: newLevel }and returnsMoveOutcome. TodaymoveHeadingSectionwrites the level to the dragged heading alone (read from code:moveHeading.ts:99-111). The planner removes that write. If it is still there when you start, stop: the planner is not merged. isTitleonTocItem. This issue reads it. Add Move rows to Section options and open the menu from the grip #501 Step 1 adds it. If it is missing when you start, add it here with the same three edits as that step. AddisTitle: booleanintypes/toc.ts, setisTitle: i === 0inbuildTocItems, and compare it intocItemsEqual. The change that lands second drops the duplicate.- Blocks Announce TOC move results and return focus after a move #507. It reads
DropTarget.noDropinhandleDragEnd, beforeresetState, to tell a header release from a release over the set. - Blocks Set the drag level from the row above and indent the drop line #504. It reads the title-start x stored in the rect cache here, and it changes the line position and the level rule.
- Blocks Start a TOC drag from the whole row and cancel it safely #505 and Drop a section onto a TOC heading to put it inside #508. Both build on this zone model and its rebuild rule.
- Blocks Run the TOC move hallway test before drop inside ships #509.
Current behaviour
All links are pinned to 85295b8cf2fc8f78efd5a3eaa4ecc05af413c2b2.
- Row choice is nearest centre.
findDropTargetscores every row by the distance from the pointer to the row centre. It switches rows only when the new row is 10px closer (read from code:utils.ts:103-118,types.ts:33-35). - Two halves with a 4px dead zone.
getPointerPositionsplits the chosen row at its 50% line (read from code:pointerCollisionDetection.ts:33-47). - Two normalisers rename the gap. The first turns "after a parent" into "before its first child". The second turns "before a sibling" into "after the previous row" (read from code:
utils.ts:132-167). Neither reads fold state. - Hidden rows stay in the cache.
buildRectCachestores a rect for every flat row (useTocDrag.ts:53-60). A row inside a folded parent isdisplay: none(_tableOfContents.scss:95-97). Its zero rect is truthy, so the normalisers accept it (read from code:utils.ts:84-89). - The cache rebuilds only at drag start and on a captured scroll (read from code:
useTocDrag.ts:75-92,:115). During a drag the set shows as a ghost: a 2px dashed border at 0.6 opacity (_tableOfContents.scss:99-112). The cache is built before.is-draggingand that border apply. Whether the border shifts rows is not measured. A fold change or a remote heading edit mid-drag leaves the rects stale (secondary / inferred). - A second source can clear the target.
handleDragOverclears the drop target when dnd-kit'soveris null or is the dragged row (useTocDrag.ts:169-174).pointerYCollisionranks every sortable, the dragged row included, by centre distance (pointerCollisionDetection.ts:3-31). So the line can drop out whilefindDropTargetstill has a target (secondary / inferred, not seen in a browser). - The header row is not a row in the model. The sticky
li.toc__headeris not inflatItems(TocDesktop.tsx:83-87,_tableOfContents.scss:69-79). A pointer over it picks the nearest row, which is "before the Title" (secondary / inferred). Rows that scroll under the sticky header keep live rects there (read from code). - The header row keeps its own cursor during a drag. The drag rule that sets
pointer-events: nonetargets.toc__item > .toc__rowonly, so it skipsli.toc__header(_tableOfContents.scss:35-61). The header row hascursor-pointer, and so does its chat icon (TocHeader.tsx:47-50,:66-80). The drag card wrapper haspointer-events: none(_tocDrag.scss:86-89), so the pointer reaches the list under the card. So a cursor written ondocument.bodycannot show over the header (read from code). - The line paints from the target rect (read from code:
utils.ts:169-180,TocDesktop.tsx:166-172). After the normalisers, each gap paints from one row. A hidden target gives a line at a zero rect.
Measured on a scratch copy, 2026-10-15. The harness copies findDropTarget, getPointerPosition and moveHeadingSection verbatim. It feeds synthetic 28px rows, with 0×0 rects for hidden rows. It is not in the repo. Read each result as "today's logic on these rects", not as a browser run.
| Case | Hit test result | Document after the drop |
|---|---|---|
| Drag A; pointer on the lower half of folded F (children F1, F2) | {"id":"F1","position":"before","indicatorY":-1.5,"rectLeft":0,"rectWidth":0} |
H1:Title p H2:F p H2:A p H3:F1 p H3:F2 p H2:G p. TOC: H2:F H2:A{H3:F1 H3:F2}. A lands inside the fold and takes F's sub-headings. |
| Drag A; pointer on the upper half of G, right after folded F | {"id":"F2","position":"after","indicatorY":1.5,"rectLeft":0,"rectWidth":0} |
The slot is right, but the line paints at a zero rect. |
| Drag H2 A (child A1); pointer on the lower half of the Title row | {"id":"Title","position":"after",...} |
H1:Title p H2:B p H2:C p H2:A p H3:A1 p. A jumps to the end of the document. |
| Drag first child A1; pointer on the lower half of its parent P | {"id":"P","position":"after",...} |
H2:P p H3:A2 p H3:A3 p H3:A1 p. A1 jumps to the end of P. |
Case 1 comes from the first normaliser, and case 2 from the second. Both accept a hidden row's zero rect (read from code). Cases 3 and 4 come from after X, which inserts at X.sectionTo, the end of X's whole section. The first normaliser skips there, because the next row is the dragged one (read from code: next.id !== activeId). The symptoms are measured on the harness; the browser confirms them in Step 0.
Target behaviour
The rect cache
- Rows. One entry per visible heading row, in list order. A row is visible when no ancestor in
flatItemshasopen: false. A row whose rect has zero height is dropped as well. - Entry shape.
TocRowRect = { id, level, top, bottom, left, width, titleX, inSet, isTitle }.levelisitem.level.titleXis the left edge of the row's.toc__row-link(TocRow.tsx:55-65). Nothing readstitleXin this issue; Set the drag level from the row above and indent the drop line #504 does.inSetis true for the dragged row and every id incollapsedIds. - Header. The cache also stores the bottom edge of
li.toc__header. - Pure builder. One pure function builds the cache from rows and a rect reader. A separate DOM reader supplies the rects. So the cache logic runs in Jest with synthetic rects.
- Rebuild. While a drag runs, rebuild in a
useLayoutEffectkeyed onflatItemsandstate.activeId. Then re-run the hit test at the last pointer Y. A layout effect runs after commit and before paint, so the line never uses the old rows for a painted frame. flatItemsalready changes on every fold change.buildTocItemswritesopen, andtocItemsEqualcompares it (read from code:useToc.ts:26-38,:72-90). A fold change rebuilds the TOC at once, without the 100ms throttle (:116-126).- Keying on
state.activeIdalso builds the cache once after the drag-start commit. So the cache sees.is-draggingand the set's dashed border. - Keep the rebuild on a captured scroll, and re-run the hit test there too. Auto-scroll moves rows under a still pointer (secondary / inferred).
Zones (this issue)
- Each target row splits at its 50% line into a before zone (top half) and an after zone (bottom half).
- The 4px dead zone at the 50% line becomes a 2px band at the zone edge (
TOC_ZONE_HYSTERESIS = 2). The current zone holds until the pointer passes the edge by 2px. Drop a section onto a TOC heading to put it inside #508 later moves the edges and adds the middle band. - Title row (
isTitle: true). No before zone. Its whole height is its after zone, so it maps to the gap below it (R3). - Set rows (
inSet: true). No zones. The pointer over them givesemptyTarget, withnoDrop: false, and a release there cancels (R6). - Header row. No zones and no line. The hit test returns
{ ...emptyTarget, noDrop: true }, and a release there cancels. CSS shows theno-dropcursor there (Step 4), if Decision A holds. - Rows inside a folded ancestor. Not in the cache, so never targets.
Row choice
- If the pointer Y is at or above the header's bottom edge, the result is "no target", with
noDrop: true. - Otherwise the row is the cache row whose
[top, bottom)holds the pointer Y. - If no row holds it (a gap between rects, or below the last row), use the nearest row by edge distance. Its zone is the edge nearer the pointer: before when the pointer is above the row, after when below.
- If that row is in the set, the result is "no target".
One canonical gap name
- The before zone of row N names
before N. - The after zone of row N names
before M. M is the next cache row after N that is not in the set. - Only when no such M exists does the after zone name
after N. - So every gap between two visible rows is "before the lower row". Never add an "after" normaliser.
- VS Code uses the same rule to stop flicker (primary source:
listView.ts:1421-1428, "Always use the before feedback if possible"). - Row N's after zone and row N+1's before zone name the same gap. So crossing a row border never changes the drop.
Where the line paints
One gap must paint one line. Nested rows sit further right than their parents (secondary / inferred from the daisyUI menu nest). So a gap painted from two different rows would jump sideways at the border.
- Before zone of row R. Paint from R. Y is
R.top - 1.5. - After zone of row R, and M is the next cache row (no set rows between). Paint from M. Y is
M.top - 1.5. This is the same line as M's before zone. - After zone of row R, with set rows between R and M. Paint from R. Y is
R.bottom + 1.5. The line stays under the pointer, above the set. - After zone of row R, with no M. Paint from R. Y is
R.bottom + 1.5. leftandwidthalways come from the paint row.INDICATOR_Y_HYSTERESIS(8px) still applies to Y.- Two edge cases. When the set sits right under the Title row, the Title's after zone paints from the Title row. When the set is parent P's first child, P's after zone paints from P.
- So both sides of a row border give the same Y,
leftandwidth. Today's normalisers also paint each gap from one row.
Why each measured case comes out right
Secondary / inferred from compute-section.ts:24-33; confirm each in the browser.
- Folded F. F's children are not in the cache, so the after zone of F names
before G. G starts atF.sectionTo, so the set lands after F's whole hidden section. - Title row. It names
before B, the next row that is not in the set. That insert point isA.sectionTo, the source's own slot, so the planner makes it a no-op. - Parent P. Its after zone skips the set row A1 and names
before A2. That isA1.sectionTo, again a no-op. - One accepted exception. An empty heading has no TOC row, because
buildTocItemsskips headings with no text (read from code:useToc.ts:78,if (!headingId || !node.textContent) continue). Sobefore Mlands after any empty heading just above M. The insert point is still a heading start.
Every name maps to the start of a heading node or the document end. before X inserts at X.pos, and after X inserts at X.sectionTo (read from code: moveHeading.ts:84). So no body paragraph changes owner.
One source of truth
- The rect-cache zone model alone sets the drop target. Delete
handleDragOver. - Keep
collisionDetection={pointerYCollision}so dnd-kit behaviour does not change. Without the prop,DndContextfalls back torectIntersection(read from code: installed@dnd-kit/[email protected],dist/core.esm.jsline 2864,collisionDetection = rectIntersection). Nothing readsoverafter this change. - Run all zone logic from pointer coordinates in
handleDragMove(useTocDrag.ts:129-167). Heading rows havepointer-events: noneduring a drag, so DOM hover never fires (_tableOfContents.scss:35-61). - One compare decides whether state changes. It covers
projectedLevel,id,position,zone,zoneRowId,indicatorY,noDropand the paint row id. The zone hysteresis readsprev.zoneandprev.zoneRowId, so they must stay current.
What stays as it is
- Level.
projectedLevelstill comes from the sideways offset (calculateProjectedLevel).handleDragEndkeeps callingmoveHeadingSectionwithnewLevel: projectedLevel(useTocDrag.ts:193-199). After Move a TOC section with its sub-headings and keep the Title fixed #500, that wrapper passes it toplanMoveasdrop.level. So the R1 cascade and R4 squash apply. This issue writes no level itself. - Modifier and picker. Do not change
tocDragModifierorTocLevelPicker. - Line. Same recipe. Only the paint-row rule above is new.
- Post-drop scroll. Keep today's editor
scrollIntoViewafter a move (useTocDrag.ts:201-209). After Move a TOC section with its sub-headings and keep the Title fixed #500, it runs only whenoutcome.kind === 'moved'.
Micro-interactions
This issue owns steps 3, 7 and 8 of the Drag timeline on #499, plus the rebuild-before-paint rule. Every cue is instant. No motion token applies, and nothing tweens.
| When | What the person sees | Timing | Reduced motion |
|---|---|---|---|
| Pointer moves over a target row or a gap | The 2px line jumps to the gap under the pointer. | Instant. No tween. | Same. |
| Pointer crosses a row border | The line stays still: same Y, left and width. Both sides name and paint one gap. |
Instant. | Same. |
| Pointer crosses a 50% line | The line moves after the pointer passes the edge by 2px. | Instant. | Same. |
| Pointer over the Title row | The line shows under the Title row, never above it. | Instant. | Same. |
| Pointer over the set | No line. Cursor stays grabbing. |
Instant. | Same. |
| Pointer over the header row | No line. Cursor no-drop (Decision A). |
Instant. | Same. |
| A fold change or a TOC rebuild mid-drag | The line re-targets before the next paint, with no pointer move. | Before paint. | Same. |
| Release with no target, over the set or over the header | Nothing moves. Today's cancel path runs (resetState). |
Instant. | Same. |
Implementation steps
Step 0. Confirm the symptom in the browser
The fold result above comes from a harness, not a browser.
-
Start
make dev-local. Read the WEBAPP port from its output. Next moves to the next free port when 3000 is busy (read from code:dev-local-preflight.ts:318). Openhttp://localhost:<WEBAPP port>/editor?localPersistence=true&docName=toc-drag-labat 1440×900 in a visible tab. -
Seed the outline in DevTools with the playground hook (
EditorPlayground.tsx:80). Use one section only. Each section title becomes an H1 (createDocumentFromStructure.ts:70-93), so a second section adds a second H1.window._createDocumentFromStructure({ sections: [{ title: 'Title', contents: [ { type: 'heading', level: 2, title: 'A' }, { type: 'heading', level: 2, title: 'F', contents: [ { type: 'heading', level: 3, title: 'F1' }, { type: 'heading', level: 3, title: 'F2' } ] }, { type: 'heading', level: 2, title: 'G' } ] }] })
You can also type the headings by hand.
-
Fold F with its chevron.
-
With a real mouse, drag A and release on the lower half of F. Note where A lands.
-
Reset with the seed call. Drag A and release on the lower half of the Title row. Note where A lands.
-
Post both results as a comment on this issue.
If neither case reproduces, stop and report before you write code.
To read F's toc-id (for the fold check in Verification), find its row by text. data-id sits on each li.toc__item (TocItemBody.tsx:149):
[...document.querySelectorAll('li.toc__item')]
.find((li) => li.querySelector(':scope > .toc__row .toc__link')?.textContent === 'F')?.dataset.idStep 1. Types
File: dnd/types.ts.
- Add
TocRowRect = { id: string; level: number; top: number; bottom: number; left: number; width: number; titleX: number; inSet: boolean; isTitle: boolean }. - Add
TocRectCache = { rows: TocRowRect[]; headerBottom: number | null }. - On
DropTarget, changerecttoTocRowRect | null. It means "the row the line paints from". AddzoneRowId: string | nullandzone: 'before' | 'after' | null. DropTarget.levelis the named row's level, fromTocRowRect.level. No code reads it today (read from code: a grep finds no reader).- Add
noDrop: boolean. It is true only for a pointer over the header row. A set row, an empty list and the start target keepnoDrop: false. Announce TOC move results and return focus after a move #507 reads it to speak the cancel line. CSS still owns the header cursor (Step 4). - Export
emptyTarget: DropTarget = { id: null, position: null, rect: null, level: 1, indicatorY: null, zoneRowId: null, zone: null, noDrop: false }. It replacesinitialDropTargetinuseTocDrag.ts:35-41. - Export
sameDropTarget(a, b). It comparesid,position,zone,zoneRowId,indicatorY,noDropandrect?.id. - Keep
position: MovePosition | null, as Move a TOC section with its sub-headings and keep the Title fixed #500 left it. This issue never producesinside. - Delete
TARGET_HYSTERESIS. AddTOC_ZONE_HYSTERESIS = 2. KeepINDICATOR_Y_HYSTERESIS.
Step 2. The pure functions
File: dnd/utils.ts.
-
Delete
findDropTarget,rectForItemand both normalisers. Never add an "after" normaliser. -
Add
visibleTocIds(flatItems): Set<string>. Walk the flat list once. After a row withopen: false, hide every following row deeper than it, until a row at its level or above. -
Add the pure builder. It never touches the DOM:
type RowBox = { top: number; bottom: number; left: number; width: number; titleX: number } buildTocRectCache(flatItems, setIds: Set<string>, rectFor: (id: string) => RowBox | null, headerBottom: number | null): TocRectCache const visible = visibleTocIds(flatItems) rows = flatItems in order, kept when visible.has(id), rectFor(id) is not null, and bottom - top > 0 each row: { id, level: item.level, ...box, inSet: setIds.has(id), isTitle: item.isTitle === true }
-
Add
hitTestDrop. It reads only the cache:hitTestDrop({ pointerY, cache, prev }): DropTarget if (cache.headerBottom !== null && pointerY <= cache.headerBottom) return { ...emptyTarget, noDrop: true } // header: the only noDrop case const rows = cache.rows if (rows.length === 0) return emptyTarget let i = rows.findIndex((r) => pointerY >= r.top && pointerY < r.bottom) let zone: 'before' | 'after' if (i === -1) { i = index of the row with min(|pointerY - r.top|, |pointerY - r.bottom|) zone = pointerY < rows[i].top ? 'before' : 'after' } else { const r = rows[i] const mid = r.top + (r.bottom - r.top) / 2 const held = prev.zoneRowId === r.id ? prev.zone : null zone = held === 'before' && pointerY < mid + TOC_ZONE_HYSTERESIS ? 'before' : held === 'after' && pointerY > mid - TOC_ZONE_HYSTERESIS ? 'after' : pointerY < mid ? 'before' : 'after' } const row = rows[i] if (row.inSet) return emptyTarget // R6: the set has no zones; noDrop stays false if (row.isTitle) zone = 'after' // R3: no before zone on the Title row let named = row, position = zone, paint = row let rawY = zone === 'before' ? row.top - 1.5 : row.bottom + 1.5 if (zone === 'after') { const j = first index after i with !rows[j].inSet // -1 when none if (j !== -1) { named = rows[j]; position = 'before' if (j === i + 1) { paint = rows[j]; rawY = rows[j].top - 1.5 } // one gap, one line } } const indicatorY = prev.indicatorY !== null && Math.abs(rawY - prev.indicatorY) < INDICATOR_Y_HYSTERESIS ? prev.indicatorY : rawY return { id: named.id, position, level: named.level, rect: paint, zoneRowId: row.id, zone, indicatorY, noDrop: false }
-
File:
pointerCollisionDetection.ts. DeletegetPointerPosition;findDropTargetis its only caller (read from code). Remove its import fromutils.ts. KeeppointerYCollision.
Step 3. The drag hook
File: hooks/useTocDrag.ts.
-
DOM reader. Replace
buildRectCache(:53-60) withreadTocRowRect(id). It readsgetItemElement(id)and its.toc__row-linkchild, and returns aRowBoxornull. A smallrebuildCache()callsbuildTocRectCache(flatItemsRef.current, setIds, readTocRowRect, headerBottom).setIdsisstateRef.current.activeIdplusstateRef.current.collapsedIds.headerBottomcomes from the header ref (Step 4). -
handleDragStart. Drop its cache build at:115. The layout effect in item 6 builds the cache after the drag-start commit. UseemptyTargetas the start target. -
retarget(nextLevel?: number). OneuseCallbackwith an empty dependency list. It reads only refs:pointerYRef, the cache ref and the state through a functionalsetState. So it is stable, and no listener can hold an old copy.setState((prev) => { if (!prev.activeId) return prev const level = nextLevel ?? prev.projectedLevel const pointerY = pointerYRef.current const drop = pointerY > 0 ? hitTestDrop({ pointerY, cache: rectCacheRef.current, prev: prev.dropTarget }) : prev.dropTarget if (level === prev.projectedLevel && sameDropTarget(drop, prev.dropTarget)) return prev return { ...prev, projectedLevel: level, dropTarget: drop } })
The updater stays pure: no DOM writes inside it. Keep the
collapsedIdsidentity, as the comment at:162asks. It skips the hit test while the pointer Y is still 0. -
handleDragMove(:129-167) keeps theprojectedLevelmath. It then callsretarget(newLevel). So the compare at:153-160goes away, and one compare remains. -
resetState(:103-106) also setspointerYRef.current = 0and an empty cache. Today the ref keeps the last Y of the previous drag (:64,:79). The new layout effect runs before the passive effect attachespointermove. Without the reset, a second drag paints a line at the old Y for a frame (read from code). -
Rebuild before paint. Add a
useLayoutEffectwith deps[flatItems, state.activeId, rebuildCache, retarget]. Whilestate.activeIdis set, it callsrebuildCache()and thenretarget(). MakerebuildCacheauseCallbackwith no changing deps (it reads refs only). Then both callbacks are stable, andreact-hooks/exhaustive-depspasses. That rule is a warning, andbun run lintallows zero warnings (read from code:packages/eslint-config/next.js). -
Captured scroll. The listener (
:81-85) callsrebuildCache()and thenretarget(). Its effect deps become[state.activeId, rebuildCache, retarget]. Both callbacks read only refs, so the listener never holds an old copy. -
Delete
handleDragOver(:169-174), itsonDragOverentry inhandlers, and thetype DragOverEventimport (:4). An unused import failsbun run lint. -
Body cursor. Keep today's
grabbingwrite and its cleanup (:78,:87-91). Do not writeno-dropfrom JavaScript; Step 4 does it in CSS. -
handleDragEnd(:176-214) keeps its shape. A target with noidcancels throughresetState, as today. Do not clearnoDropbefore that point; Announce TOC move results and return focus after a move #507 reads it there. Pass the namedid,positionandnewLevel: projectedLeveltomoveHeadingSection.
Step 4. The header element and its cursor
File: TocDesktop.tsx.
- Put a ref on the header
liand pass it as a second argument:useTocDrag(items, headerRef)(:38). Do not query the header by a global selector. DropIndicatorPortalkeeps readingdropTarget.rect.leftand.width(:166-172).rectis now the paint row, aTocRowRect.- Keep
collisionDetection={pointerYCollision}. The{...handlers}spread dropsonDragOveron its own.
File: apps/webapp/src/styles/components/_tableOfContents.scss. Ship this only if Decision A holds. If there is no ruling when work starts, build every other step, leave this SCSS out, and skip the cursor checks. The fix must not wait on the cursor ruling. Add it inside the .toc__list.is-dragging block:
// Header is never a drop target: show no-drop, and skip its pointer-cursor row.
> .toc__header {
cursor: no-drop;
> .toc__row {
pointer-events: none;
}
}- Why it works: the
listays the hit target, so its cursor shows. The row and its chat button inheritpointer-events: none, so theircursor-pointernever applies. No file incomponents/toc/setspointer-events: auto(read from code: a grep finds none). - It mirrors the existing
.toc__item > .toc__rowrule, so the header hover fill also stops during a drag. - Do not set
pointer-events: noneon theliitself. The pointer would then fall through to the rows under the sticky header, and the cursor would readgrabbing. - Run
bun run lint:styles.
Step 5. Changelog
Add one line under ## [Unreleased], in a ### Fixed heading (add the heading if it is missing), in apps/webapp/CHANGELOG.md. Suggested text: "A TOC drop below a folded row now lands after its whole section, not inside the fold."
Step 6. Review and verify
Run the checks in Verification. Then do the browser checks in Acceptance criteria. Stop for review.
Out of scope
- The D1 gap-level rule, hard case 11, the D2 offset removal and the D8 indented line. They belong to Set the drag level from the row above and indent the drop line #504.
- The whole-row drag start,
draggable={false}on the title link and every cancel path. They belong to Start a TOC drag from the whole row and cancel it safely #505. - The inside zone, the H6 rule and spring-open. They belong to Drop a section onto a TOC heading to put it inside #508.
- The card fade, flash, toast and settle scroll. They belong to Show where a moved section landed after a TOC move #506. Keep today's post-drop scroll until then.
- Auto-scroll tuning. dnd-kit defaults stay; the hallway test may tune them.
- Clipping rows to the scroller's bottom edge. Only the sticky header gets a no-target rule here.
Decisions
Owner: the maintainer. The tracker's Decisions cover the level and the line. These two letters are local to this issue; they are not tracker D-numbers.
Decision A. Show no-drop over the header row during a drag?
- Recommended: yes, in CSS only (Step 4). The header can never take a drop, and a stock cursor says so with no new visual.
- Peer check. No Google Docs, Word or Notion source states this cue. The [Tracking] Move TOC sections like folders: cascade, drop inside, and a menu path #499 Drag timeline names it at step 8 only as Decision A. MDN defines the value (primary source: MDN
cursor, "An item may not be dropped at the current location."). AGENTS.mdsays: "If they disagree, or no primary source states the behaviour, say so and ask the maintainer" (AGENTS.md:151). If kept, record it as a deliberate exception on [Tracking] Move TOC sections like folders: cascade, drop inside, and a menu path #499.- Run the TOC move hallway test before drop inside ships #509 task 6b checks whether people read the cue.
- Alternative. Skip the SCSS. The header keeps its
pointercursor, as today. A release there still cancels. - The value is not a token, species, size, radius, shadow or ink step (read from code:
design-system.md:9-25).
Decision B (design-system ruling). Does the catalog get a line for this cursor?
- Recommended: yes, if Decision A holds. Add one clause to the "drag states" row: "header row
no-dropcursor". Catalog rows must stay true to the shipped states. - The row is in §Table of contents at
design-system.md:401. The TOC drag system rows at:407-417cover the grip, card, deck and picker, not list states. - Alternative. No catalog line, because a stock cursor is not a recipe.
- The design system is locked, so this edit lands only with the maintainer's ruling.
Acceptance criteria
Browser checks use real pointer events: a mouse or trackpad, or CDP Input.dispatchMouseEvent press, move and release. cy.dragTocItem calls window._moveHeading and skips dnd-kit, so it proves nothing about zones (commands.ts:920-996). Run each check at 1440×900 in a visible tab. Run it in light and in dark.
- Step 0 results are posted on this issue.
- A drop in the lower half of a folded row lands after its whole hidden section. The folded row keeps its sub-headings.
- A drop in the upper half of the row after a folded row lands in the same place. The line paints at that row's top, not at the top of the window.
- Dragging the first H2 with no sideways offset and releasing on the lower half of the Title row changes nothing. The line shows under the Title row.
- Dragging a first child with no sideways offset and releasing on the lower half of its parent changes nothing.
- The drop line never shows above the Title row.
- Over the header row no line shows, and a release there changes nothing. React DevTools shows
dropTarget.noDrop: truethere andfalseover the set. If Decision A holds, the cursor isno-dropthere, over the title text and over the chat icon. - Over the set no line shows and the cursor stays
grabbing. A release there changes nothing. - If Decision A holds, moving the pointer from the set to the header and back flips the cursor each time, with no line.
- While the pointer stays over target rows and gaps, the target never flickers to empty. A screen recording at normal speed shows no line drop-out.
- Moving across the border between two rows does not move the line: not its Y, not its
left, not its width. Check it between a parent and its first child. - Folding or unfolding a row during a drag re-targets at the same pointer, with no pointer move.
- On a second drag, the first painted line sits under the pointer, not where the last drag ended.
- A sideways drag still changes the level exactly as before this change.
-
handleDragOver,findDropTarget,getPointerPosition,TARGET_HYSTERESISand theDragOverEventimport are gone. A grep finds no "after" normaliser. - No new token, size, radius, shadow or ink step lands.
- Static checks, webapp Jest and the TOC Cypress spec pass. The CHANGELOG line is in the same change.
Verification
Bun only. Do not run next build while the dev server is live (AGENTS.md §Test Policy, AGENTS.md:110).
bun run --filter @docs.plus/webapp typecheck
bun run lint
bun run lint:styles
bun run --filter @docs.plus/webapp test
# with `make dev-local` running; read the WEBAPP port it prints
BASE_URL=http://localhost:<WEBAPP port> bash scripts/run-tests.sh --e2e --scope editorrun-tests.sh defaults BASE_URL to port 3001, so pass it (read from code: run-tests.sh:22). The spec apps/webapp/cypress/e2e/editor/toc/toc-render-and-drag.cy.js must stay green. It proves order and HeadingScale after a programmatic move, not zones.
Fold re-target check. On the playground, seed the outline from Step 0 and read F's toc-id with the Step 0 snippet. In DevTools run setTimeout(() => window._editor.commands.toggleFold('<F toc-id>'), 3000). Start a drag of A and hold the pointer still below F. The line must move when F changes, with no pointer move.
Optional unit test. AGENTS.md §Test Policy allows one, because buildTocRectCache plus hitTestDrop is a pure projection with dense branching (AGENTS.md:104-105). It is not required.
- The failure mode: a pointer on the lower half of a folded row names a hidden child row. The section then lands inside the fold.
- If you add it, put it at
apps/webapp/src/components/toc/dnd/hitTestDrop.test.ts. Run both pure functions together:hitTestDrop({ pointerY, cache: buildTocRectCache(...), prev: emptyTarget }). - Give every row a non-zero synthetic rect, hidden rows included (for example 28px rows stacked in list order). Then only
visibleTocIdskeeps hidden rows out of the cache. - Use the four measured cases above as rows, with the expected
{ id, position }from §Why each measured case comes out right. Add one row each for the header ({ ...emptyTarget, noDrop: true }), a set row (emptyTarget,noDrop: false) and a row border (sameindicatorYandrect.idon both sides). - Prove it by sabotage: let
visibleTocIdsreturn every id, and see the fold row fail (it names F1). Then restore it and see it green.
Docs to update
apps/webapp/CHANGELOG.md: the one### Fixedline in Step 5.docs/DEMO.md§Moving a section names no drop zone, so it needs no change here (DEMO.md:222-231). Move a TOC section with its sub-headings and keep the Title fixed #500 rewrites line 229..cursor/docs/design-system.md: one clause on the "drag states" row at line 401, only if Decisions A and B both hold. Otherwise no change. The line and the set's dashed look keep their recipes.
Read first
AGENTS.md§Test Policy, §Workflow And Review Expectations (line 151, the peer rule) and §Simplified English Mandate.apps/webapp/CLAUDE.md§TOC And Heading Actions (CLAUDE.md:279-311). Read the rules on the TOC row as a daisyUI menu item, the grip chip, theDragOverlayportal and theToc*names.apps/webapp/CLAUDE.md§Motion System. This issue adds no motion; keep every drop cue instant.apps/webapp/src/components/TipTap/CLAUDE.md§Heading Schema, for the flat schema andcomputeSection..cursor/docs/design-system.md§Change protocol (locked), the "drag states" row and the TOC drag catalog rows (design-system.md:401-417).- [Tracking] Move TOC sections like folders: cascade, drop inside, and a menu path #499 Shared rules and its Drag timeline.
Generated by Claude Code
Activity
HMarzban commentedon Nov 3, 2026
Status, 2026-11-03. Nothing from this issue is in the 2026-11-03 push (
a9b0c69e8..8e25e83df). The hit test is unchanged, so the folded-row and Title-row cases in this issue still reproduce.Left:
HMarzban commentedon Nov 5, 2026
Fixed on main and pushed.
Covered by
toc-drag-pointer.cy.js("lands a drop below a folded row after its whole section").