facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.91k stars 1.69k forks source link

Bug: Triple click selection doesn't remove all content if the selected node ends in a link node #5049

Open 9larsons opened 1 year ago

9larsons commented 1 year ago

Lexical version: v0.12.2

Steps To Reproduce

  1. Add text to a paragraph like 'one two'
  2. Add a link on the last text (make sure the last child node of the paragraph is a link node)
  3. Triple click to select all of the paragraph's content
  4. Hit delete (note: you need the text to be sufficient long for the link, as this is related to the offset)

The current behavior

https://github.com/facebook/lexical/assets/21961100/dd8a95e4-f7f8-4aa3-8d2a-f3051a3b9234

The expected behavior

Delete all content in the paragraph.

9larsons commented 1 year ago

https://github.com/facebook/lexical/blob/176b8cf16ecb332ee5efe2c75219e223b7b019f2/packages/lexical/src/LexicalSelection.ts#L1076-L1091

In this case, when calling insertText(''), the selected nodes are the text nodes and, ultimately, the child text node of the link node. The problem is that lastNode uses the offset used by the parentNode (the paragraph), clipping the text. It should use the getTextContentLength() value because it should be grabbing the entire node.

kevinansfield commented 1 year ago

@9larsons I can't replicate this when testing with the fix in https://github.com/facebook/lexical/pull/5053 - can you confirm?

9larsons commented 1 year ago

@kevinansfield agreed - the root cause is the same here. The fix you proposed to #5053 works for this as well.