facebook / lexical

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

Bug: Pasting over content starting with an empty node appends instead of replace #6763

Open orelbn opened 1 month ago

orelbn commented 1 month ago

Pasting over content that starts with an empty node leads to appending instead of replacement.

https://github.com/user-attachments/assets/9ed8bd65-6a1e-4312-979f-f5635a7691a8

Lexical version: 0.18.1+dev.esm

Steps To Reproduce

  1. go to playground. Press 'Enter'.
  2. Type any text or insert any block in the 2nd line
  3. Select all, then press paste

The current behavior

Appends to the selected content instead of replacing it on paste

The expected behavior

The text that is selected should replaced not append to.

Impact of fix

Pasting content is pretty fundamental to a text editor. This behaviour can lead to weird behaviours for all users.

orelbn commented 1 month ago

I believe it has to do with this function.

https://github.com/facebook/lexical/blob/409c65e56e447452da6fa7022672aeb3392518ca/packages/lexical/src/LexicalSelection.ts#L1334-L1341

I tried to figure it out myself, but the function's assumptions in the third case are unclear to me.

hunxjunedo commented 4 weeks ago

@trueadm hey, I'd like to contribute to this one. Mind assigning?

etrepum commented 4 weeks ago

@hunxjunedo there's no need for assignment, when/if you have a solution then you can submit a PR