Review: PR #1438 Select cards in reading order across grids and lists
Code review of PR #1438 (feat/node-range-selection), with one confirmed blocking bug, verification results and the logs.

Review of PR #1438: Select cards in reading order across grids and lists, branch feat/node-range-selection, head commit 501eb3a97.

Verdict: request changes. One confirmed bug breaks the main use case in typical Seed documents: ranges that cross a heading. Everything else is mostly solid and well tested. The full logs are in Logs: PR #1438 review.

Verification

    Typecheck (pnpm --filter @shm/editor typecheck): passes.

    Unit tests (pnpm --filter @shm/editor test): 541 passed, 1 failed. The failing test is embed-editor.test.tsx > configures embedded read-only links with the platform URL handler. This PR doesn't touch that file. It wasn't re-run on main.

    E2E card-selection.e2e.ts: 19 of 19 passed, twice.

    E2E shift-arrow-selection.e2e.ts: 8 of 8 passed, twice. No flakiness between runs.

    Console: ProseMirror logs TextSelection endpoint not pointing into a node with inline content (blockNode) once per test page. That's 17 times per card-selection run and 6 times per shift-arrow run.

    Repro for the heading bug below: a temporary e2e test, deleted after running. Its output is in the logs.

Blocking

1. A range that crosses a heading selects nothing, and Delete leaves empty paragraphs

detectFullySelectedBlocks in FullBlockSelectionPlugin.ts returns an empty list whenever the selection covers a heading's text and also goes past it. That guard was written for drag-selecting text out of a heading (selectionSpansOutsideHeadingContent). The new range selection relies on that list for everything: the outline on selected cards, Delete/Backspace (deleteSelectedBlocks) and multi-block drag. So all of them break when a heading is in the range.

Reproduced in the e2e harness:

Doc: paragraph, card-a, heading, card-b Click card-a, shift-click card-b → BlockRangeSelection from 6 to 21, fullBlockIds: [], outlinedBlockIds: [] Backspace → ["paragraph", "paragraph"] Doc: paragraph, card-a, heading > [card-b], paragraph Click card-a, shift-click card-b → BlockRangeSelection from 6 to 21, fullBlockIds: [], outlinedBlockIds: [] Backspace → ["paragraph", "paragraph", "paragraph"]

Nothing shows as selected. Backspace falls back to the default deleteSelection, which leaves the empty blocks that the PR description says are fixed. Headings with nested section content are very common in Seed documents, so this would come up all the time.

Suggested fix: skip the heading guard when either end of the range sits at a block's edge rather than in text. Add a heading case to card-selection.e2e.ts; no test there uses a heading.

Should fix

2. Delete can change list semantics

deleteSelectedBlocks moves a deleted block's nested blocks up into the parent's list, but that list's type stays as it is. Children of a Grid or an Ordered list would quietly become ordinary siblings in whatever list the parent was in. This is from reading the code; it wasn't tested. The PR describes the behaviour, but the list-type case isn't covered.

3. Only Delete and Backspace use the new removal

Cut, typing over the selection and paste still go through ProseMirror's default replace. They will probably leave empty blocks in the same way. This wasn't tested. Either handle them too, or say in the PR that they're out of scope.

4. New setTimeout calls in the formatting toolbar

handleGroupTypeChange (Grid) and handleColumnCountChange in hm-formatting-toolbar.tsx now wrap their work in setTimeout. They only work because timers run in the order they were set, after the setTimeout already inside updateGroupCommand. That's fragile, and AGENTS.md asks not to fix timing problems with timeouts. A cleaner option is for updateGroupCommand to do the grid setup itself, or to accept a callback.

5. The formatting toolbar now appears for every single selected card

isInlineNodeSelection in FormattingToolbarPlugin.ts now lets the toolbar show for a NodeSelection of any block-group node: image, file, embed, button and so on, not only for multi-card ranges. Images and other media already show MediaSelectionMenu when selected, so check that the two don't overlap. This wasn't checked visually, and the PR has no before/after screenshots, which frontend/AGENTS.md asks for UI changes.

Nits

    Console warning. BlockRangeSelection extends TextSelection with ends at block edges, which causes the console warning above. It's harmless, but a comment saying it's expected, or a Selection subclass, would help. toJSON also writes the selection as type: 'text', so anything that saves and restores it gets a plain TextSelection back.

    Shift+Up/Down at a line edge. handleShiftArrow calls view.endOfTextblock(dir, fromHead) with a temporary state. ProseMirror applies that state to the view and then switches back, so plugin views probably update twice on each key press. Worth checking for toolbar flicker.

    Slow block lookup. adjacentBlock walks the whole document, including the text inside every block, on each Shift+Arrow. Returning false for text blocks would skip their content.

    Double-click on punctuation. In DoubleClickPastText, a line ending in punctuation ("…world.") places a cursor instead of selecting "world". Selecting the last word-like segment would fit better.

Looks good

    Removing MultipleNodeSelection and the leftover blue-square debug decorations (SelectionPlugin, ClickSelectionPlugin, the old Shift-ArrowLeft shortcut).

    BlockRangeSelection handles mapping and undo/redo bookmarks properly, and it has unit tests.

    Filtering out selected nested blocks in executeBlockMove fixes the duplication on drag.

    The drag preview change (renderBlocksDragPreview) is clean.

    Broad e2e coverage for grids, nested cards, upload placeholders, buttons, math, embeds and Shift+Arrow.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Connections0
Linked document · Outgoing linkLinked documentReview: PR #1438 Select cards in reading order across grids and listsReview: PR #1438 Select c…
Citations 0Children & links 1

Loading child documents…

Connections show where other documents or comments link to this document.

Related documents

Loading connections…