Skip to content

fix(md-tables): require a long press before touch cell selection - #5930

Merged
404Wolf merged 3 commits into
mainfrom
cursor/mobile-table-long-press-selection-07f4
Sep 2, 2026
Merged

404Wolf merged 3 commits into
mainfrom
cursor/mobile-table-long-press-selection-07f4

Conversation

@404Wolf

@404Wolf 404Wolf commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

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's registerTableSelectionObserver installs a window-level pointerdown handler that starts a drag selection for any pointer type. It sets the anchor cell on pointerdown and, from the first pointermove, 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 by createPointerHandlers, 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 tableTouchSelection assumed 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

tableTouchDragGuard keeps touch pointermove from 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 tablePlugin rather than by the touch-selection plugin, for two reasons:

  • The channel, comment, and chat editors register tablePlugin but not the touch gesture, so touch could only ever select cells there by accident.
  • In read-only documents the touch gesture bails out on 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:

drag with no pause press and hold
before 2 cells selected, persisting after lift 1 cell
after 0 cells 1 cell

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

The existing suite modelled touch pointermove with buttons: 0 and a document target, which is not what a device sends — that is why it passed while the bug shipped. The helper now sets buttons: 1 on 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/web suite 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 test on this branch under Linux needs #5946 first.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

@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>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a89acaf-1cfe-447e-94d3-99d308656fea

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac7023 and 0d2eaf8.

📒 Files selected for processing (4)
  • apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tablePlugin.ts
  • apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTouchDragGuard.ts
  • apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTouchSelection.test.ts
  • apps/web/src/lib/core/component/LexicalMarkdown/plugins/tables/tableTouchSelection.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved touch interactions in tables so scrolling does not accidentally select or drag table cells.
    • Preserved mouse and pen drag selection behavior on desktop.
    • Added cleanup handling for interrupted or completed touch gestures.

Walkthrough

The 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 0d2ea

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)
Check name Status Explanation
Title check ✅ Passed The title uses conventional commit format with the fix: prefix, is 64 characters long, and accurately describes the touch-selection change.
Description check ✅ Passed The description clearly explains the touch-selection bug, the tableTouchDragGuard fix, affected behavior, test coverage, and scope of the changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

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>
@404Wolf
404Wolf marked this pull request as ready for review August 26, 2026 14:17
@404Wolf
404Wolf merged commit 7dea5a2 into main Sep 2, 2026
35 of 43 checks passed
@404Wolf
404Wolf deleted the cursor/mobile-table-long-press-selection-07f4 branch September 2, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants