Skip to content

Rebuild the TOC drop hit test so folded rows and gaps land right #503

Closed

Description

@HMarzban

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

Current behaviour

All links are pinned to 85295b8cf2fc8f78efd5a3eaa4ecc05af413c2b2.

  1. Row choice is nearest centre. findDropTarget scores 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).
  2. Two halves with a 4px dead zone. getPointerPosition splits the chosen row at its 50% line (read from code: pointerCollisionDetection.ts:33-47).
  3. 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.
  4. Hidden rows stay in the cache. buildRectCache stores a rect for every flat row (useTocDrag.ts:53-60). A row inside a folded parent is display: none (_tableOfContents.scss:95-97). Its zero rect is truthy, so the normalisers accept it (read from code: utils.ts:84-89).
  5. 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-dragging and 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).
  6. A second source can clear the target. handleDragOver clears the drop target when dnd-kit's over is null or is the dragged row (useTocDrag.ts:169-174). pointerYCollision ranks every sortable, the dragged row included, by centre distance (pointerCollisionDetection.ts:3-31). So the line can drop out while findDropTarget still has a target (secondary / inferred, not seen in a browser).
  7. The header row is not a row in the model. The sticky li.toc__header is not in flatItems (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).
  8. The header row keeps its own cursor during a drag. The drag rule that sets pointer-events: none targets .toc__item > .toc__row only, so it skips li.toc__header (_tableOfContents.scss:35-61). The header row has cursor-pointer, and so does its chat icon (TocHeader.tsx:47-50, :66-80). The drag card wrapper has pointer-events: none (_tocDrag.scss:86-89), so the pointer reaches the list under the card. So a cursor written on document.body cannot show over the header (read from code).
  9. 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 flatItems has open: false. A row whose rect has zero height is dropped as well.
  • Entry shape. TocRowRect = { id, level, top, bottom, left, width, titleX, inSet, isTitle }. level is item.level. titleX is the left edge of the row's .toc__row-link (TocRow.tsx:55-65). Nothing reads titleX in this issue; Set the drag level from the row above and indent the drop line #504 does. inSet is true for the dragged row and every id in collapsedIds.
  • 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 useLayoutEffect keyed on flatItems and state.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.
  • flatItems already changes on every fold change. buildTocItems writes open, and tocItemsEqual compares 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.activeId also builds the cache once after the drag-start commit. So the cache sees .is-dragging and 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 gives emptyTarget, with noDrop: 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 the no-drop cursor there (Step 4), if Decision A holds.
  • Rows inside a folded ancestor. Not in the cache, so never targets.

Row choice

  1. If the pointer Y is at or above the header's bottom edge, the result is "no target", with noDrop: true.
  2. Otherwise the row is the cache row whose [top, bottom) holds the pointer Y.
  3. 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.
  4. 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.
  • left and width always 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, left and width. 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 at F.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 is A.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 is A1.sectionTo, again a no-op.
  • One accepted exception. An empty heading has no TOC row, because buildTocItems skips headings with no text (read from code: useToc.ts:78, if (!headingId || !node.textContent) continue). So before M lands 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, DndContext falls back to rectIntersection (read from code: installed @dnd-kit/[email protected], dist/core.esm.js line 2864, collisionDetection = rectIntersection). Nothing reads over after this change.
  • Run all zone logic from pointer coordinates in handleDragMove (useTocDrag.ts:129-167). Heading rows have pointer-events: none during 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, noDrop and the paint row id. The zone hysteresis reads prev.zone and prev.zoneRowId, so they must stay current.

What stays as it is

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.

  1. 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). Open http://localhost:<WEBAPP port>/editor?localPersistence=true&docName=toc-drag-lab at 1440×900 in a visible tab.

  2. 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.

  3. Fold F with its chevron.

  4. With a real mouse, drag A and release on the lower half of F. Note where A lands.

  5. Reset with the seed call. Drag A and release on the lower half of the Title row. Note where A lands.

  6. 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.id

Step 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, change rect to TocRowRect | null. It means "the row the line paints from". Add zoneRowId: string | null and zone: 'before' | 'after' | null.
  • DropTarget.level is the named row's level, from TocRowRect.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 keep noDrop: 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 replaces initialDropTarget in useTocDrag.ts:35-41.
  • Export sameDropTarget(a, b). It compares id, position, zone, zoneRowId, indicatorY, noDrop and rect?.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 produces inside.
  • Delete TARGET_HYSTERESIS. Add TOC_ZONE_HYSTERESIS = 2. Keep INDICATOR_Y_HYSTERESIS.

Step 2. The pure functions

File: dnd/utils.ts.

  • Delete findDropTarget, rectForItem and both normalisers. Never add an "after" normaliser.

  • Add visibleTocIds(flatItems): Set<string>. Walk the flat list once. After a row with open: 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. Delete getPointerPosition; findDropTarget is its only caller (read from code). Remove its import from utils.ts. Keep pointerYCollision.

Step 3. The drag hook

File: hooks/useTocDrag.ts.

  1. DOM reader. Replace buildRectCache (:53-60) with readTocRowRect(id). It reads getItemElement(id) and its .toc__row-link child, and returns a RowBox or null. A small rebuildCache() calls buildTocRectCache(flatItemsRef.current, setIds, readTocRowRect, headerBottom). setIds is stateRef.current.activeId plus stateRef.current.collapsedIds. headerBottom comes from the header ref (Step 4).

  2. handleDragStart. Drop its cache build at :115. The layout effect in item 6 builds the cache after the drag-start commit. Use emptyTarget as the start target.

  3. retarget(nextLevel?: number). One useCallback with an empty dependency list. It reads only refs: pointerYRef, the cache ref and the state through a functional setState. 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 collapsedIds identity, as the comment at :162 asks. It skips the hit test while the pointer Y is still 0.

  4. handleDragMove (:129-167) keeps the projectedLevel math. It then calls retarget(newLevel). So the compare at :153-160 goes away, and one compare remains.

  5. resetState (:103-106) also sets pointerYRef.current = 0 and 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 attaches pointermove. Without the reset, a second drag paints a line at the old Y for a frame (read from code).

  6. Rebuild before paint. Add a useLayoutEffect with deps [flatItems, state.activeId, rebuildCache, retarget]. While state.activeId is set, it calls rebuildCache() and then retarget(). Make rebuildCache a useCallback with no changing deps (it reads refs only). Then both callbacks are stable, and react-hooks/exhaustive-deps passes. That rule is a warning, and bun run lint allows zero warnings (read from code: packages/eslint-config/next.js).

  7. Captured scroll. The listener (:81-85) calls rebuildCache() and then retarget(). Its effect deps become [state.activeId, rebuildCache, retarget]. Both callbacks read only refs, so the listener never holds an old copy.

  8. Delete handleDragOver (:169-174), its onDragOver entry in handlers, and the type DragOverEvent import (:4). An unused import fails bun run lint.

  9. Body cursor. Keep today's grabbing write and its cleanup (:78, :87-91). Do not write no-drop from JavaScript; Step 4 does it in CSS.

  10. handleDragEnd (:176-214) keeps its shape. A target with no id cancels through resetState, as today. Do not clear noDrop before that point; Announce TOC move results and return focus after a move #507 reads it there. Pass the named id, position and newLevel: projectedLevel to moveHeadingSection.

Step 4. The header element and its cursor

File: TocDesktop.tsx.

  • Put a ref on the header li and pass it as a second argument: useTocDrag(items, headerRef) (:38). Do not query the header by a global selector.
  • DropIndicatorPortal keeps reading dropTarget.rect.left and .width (:166-172). rect is now the paint row, a TocRowRect.
  • Keep collisionDetection={pointerYCollision}. The {...handlers} spread drops onDragOver on 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 li stays the hit target, so its cursor shows. The row and its chat button inherit pointer-events: none, so their cursor-pointer never applies. No file in components/toc/ sets pointer-events: auto (read from code: a grep finds none).
  • It mirrors the existing .toc__item > .toc__row rule, so the header hover fill also stops during a drag.
  • Do not set pointer-events: none on the li itself. The pointer would then fall through to the rows under the sticky header, and the cursor would read grabbing.
  • 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

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?

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-drop cursor". 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-417 cover 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: true there and false over the set. If Decision A holds, the cursor is no-drop there, 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_HYSTERESIS and the DragOverEvent import 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 editor

run-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 visibleTocIds keeps 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 (same indicatorY and rect.id on both sides).
  • Prove it by sabotage: let visibleTocIds return 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 ### Fixed line 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, the DragOverlay portal and the Toc* 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 and computeSection.
  • .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

  1. added
    bug
    Toc
    on Oct 16, 2026
  2. added this to the v2.3.0 milestone on Oct 19, 2026
  3. HMarzban commented on Nov 3, 2026

    @HMarzban
    CollaboratorAuthor

    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:

  4. HMarzban commented on Nov 5, 2026

    @HMarzban
    CollaboratorAuthor

    Fixed on main and pushed.

    • dd287cbfb: the hit test picks a gap between visible rows. A folded row has no height, so a drop below it lands after its whole section.
    • 8d4ef6057: the TOC finds all rows with one scoped query per drag, and re-measures at most once per frame on scroll. A row's top and bottom quarters are gaps, and its middle half is a drop onto the row.

    Covered by toc-drag-pointer.cy.js ("lands a drop below a folded row after its whole section").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DesktopTocUIbug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions