Repository navigation
fix(md-tables): require a long press before touch cell selection - #5930
Conversation
@lexical/table starts a drag selection from the first pointermove after a pointerdown on a cell, and a finger in contact with the screen reports the primary button as pressed, so scrolling a document past a table lit up every cell the finger crossed. Keep touch pointermove away from that window-level handler for the whole gesture, leaving the long-press gesture in tableTouchSelection as the only way a touch selects cells. Mouse and pen drags are unaffected. The guard is registered by tablePlugin, so the channel, comment, and chat editors get it too even though they do not register the touch gesture. Co-authored-by: Wolf Mermelstein <wolf@404wolf.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe table plugin now registers a touch drag guard. The guard detects primary touch gestures in table cells and blocks matching document-level movement events until the gesture ends or the editor root changes. Touch selection no longer stops movement propagation directly. Tests cover touch scrolling, pre-long-press movement, unregistered editors, and continued mouse drag selection. Merge Risk: ⚪ Minimal · up to The change limits touch cell selection to the intended long-press gesture while preserving mouse selection, and no actionable merge-blocking risk remains at the current head. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The three per-area vitest configs passed a relative tsconfigPaths root, which vite-tsconfig-paths resolves against the working directory rather than the config file. Tests run from apps/web, so '../../../' pointed above the repository root and the plugin crawled the entire filesystem looking for tsconfigs. On Linux that crawl reaches /proc and fails with EINVAL, so `bun run test` could not start at all; elsewhere it just wasted the walk. Resolve the intended apps/web root from the config file's own URL instead. Co-authored-by: Wolf Mermelstein <wolf@404wolf.com>
This reverts commit 31ef849.
Problem
Scrolling a document past a table on a phone selects cells. Touch a cell, drag, and every cell the finger crosses lights up — no pause required, and the selection stays after the finger lifts.
The intended gesture already exists in
tableTouchSelection: press and hold ~400ms, the cell lights up, and only then does a drag extend the selection. It was never the only path to a selection.@lexical/table'sregisterTableSelectionObserverinstalls a window-levelpointerdownhandler that starts a drag selection for any pointer type. It sets the anchor cell on pointerdown and, from the firstpointermove, turns the crossed cell into a focus cell. Its one touch guard (if (event.pointerType !== 'touch')around the anchor assignment) is defeated two lines later bycreatePointerHandlers, which sets the anchor anyway "to handle direct drag without clicking first". Its move handler gates on(event.buttons & 1) === 1, and a finger in contact with the screen reports the primary button as pressed, so a pan over a table is indistinguishable from a mouse drag as far as that handler is concerned.The comment in
tableTouchSelectionassumed the browser claimed the touch drag for scrolling before those handlers saw movement. It does not: the pointermoves fire, the selection is made, and it survives the pan.Fix
tableTouchDragGuardkeeps touchpointermovefrom reaching that window-level handler for the whole gesture, leaving the long-press gesture as the only way a touch selects cells. It stops propagation on the document, which leaves other document-level listeners (the cell resizer, the long-press gesture itself) intact and only cuts off the window listeners further up the path. Mouse and pen are untouched, so desktop drag-to-select still works.The guard is registered by
tablePluginrather than by the touch-selection plugin, for two reasons:tablePluginbut not the touch gesture, so touch could only ever select cells there by accident.editor.isEditable()while the upstream handler kept running.The redundant
stopPropagation()inside the long-press move handler is removed now that the guard covers the whole gesture.Evidence
Same injected touch gesture (three ~80px moves down a 61px-row table, no pause), driven through Chrome's touch pipeline against the local stack on a 390×780 viewport, with the guard off and on:
Before: a plain touch drag selects two cells
After: the same drag selects nothing
After: press and hold selects the pressed cell
mobile_table_drag_vs_hold_demo.mp4
Tests
apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTouchSelection.test.tsThe existing suite modelled touch
pointermovewithbuttons: 0and adocumenttarget, which is not what a device sends — that is why it passed while the bug shipped. The helper now setsbuttons: 1on moves and the drag tests dispatch from the pressed cell, matching how touch pointer events are targeted.Added:
scrolls instead of selecting when the drag starts before the long press— a finger that pans across three cells selects nothing, during or after the gesture.leaves the caret alone when a table is only scrolled past— same guarantee in an editor that never registers the touch gesture.still lets a mouse drag select cells— pins the desktop path the guard must not break.All three fail without the guard; the mouse test passes both ways. The seven table suites pass (48 tests), and the full
apps/websuite passed when this was verified together with #5946 (357 files, 3416 tests).Note on history
This branch briefly carried an unrelated vitest config fix, needed to run the suite on Linux at all. It now lives in #5946 and is reverted here, so this PR's diff is only the four table files. Running
bun run teston this branch under Linux needs #5946 first.To show artifacts inline, enable in settings.