[lexical] Bug Fix: narrow triple-click selection to one line#8490
[lexical] Bug Fix: narrow triple-click selection to one line#8490abhinavgautam01 wants to merge 7 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
This will be much shorter and simpler using the NodeCaret APIs that I suggested in the previous review. Code size is important, especially in the core lexical package.
…caret mock cleanup for tsc
Reworked the line-boundary walk to use $getTextPointCaret, sibling for…of iteration (same NodeCaret / PointCaret path as other caret code), and getParentCaret('root') to climb out of inline subtrees, with the shared loop factored into $walkTripleClickLineCaretBounds so $getTripleClickLineTextNodeBounds stays small. Also fixed ci-check: the test helper no longer uses delete on doc.caretRangeFromPoint (TS2790)—it restores the previous implementation instead... |
Triple-clicking is overridden by Lexical to avoid "selection overflow" edge cases, and the resulting selection behavior is undesirable -- it selects the entire block (the `<p>` tag contents) and not the line. This bug was reported upstream at facebook/lexical#7592 in June 2025. This PR implements a `VisualLineSelectionExtension` that will, on a triple-click, clamp the selection to a contiguous run of nodes bounded by line breaks. It also handles a triple-click-drag to select multiple lines. There is an upstream branch in-progress at facebook/lexical#8490, but its scope is narrower and only handles a triple-click on a text node within a single block. This extension additionally covers: - Triple-click-drag (forward and backward) - Cross-block selection when the drag spans multiple blocks - Line-granular drag — single line, multi-line in a block, and multi-line across blocks - Decorator-aware fall-through so attachments still NodeSelect - Clicking on nodes other than text nodes (e.g., whitespace between nodes or at end-of-line) 🤖 Assisted by Claude
|
ping @etrepum |
|
Just wanted to note I've opened an alternative PR at #8517 that removes the triple-click handler from |
Description
In multiline blocks (e.g. code blocks, multi-line quotes, plain-text layouts), a triple-click often causes the browser to select the entire container instead of the line under the pointer. Lexical already reads the DOM selection for triple-click (
clickwithdetail === 3), so the editor kept that over-broad range.This PR adds
$tryNormalizeTripleClickLineSelection, which usescaretPositionFromPoint/caretRangeFromPointat the event coordinates to find the intended line, then narrows the selection to:\n-delimited line when the content lives in a singleTextNode, orLineBreakNodemarkers when the block uses line breaks as siblings.The
clickhandler (onClickinLexicalEvents) runs this before the existing cross-node triple-click workaround, so behavior stays compatible when normalization does not apply.Closes Bug: Triple-click make wrong selection #7592
Test plan
Before
After
pnpm run test-unit -- packages/lexical/src/__tests__/unit/LexicalSelection.test.ts(includes Regression Bug: Triple-click make wrong selection #7592: multilineTextNodeandLineBreakNode-separated lines, with mocked caret APIs)