lexical icon indicating copy to clipboard operation
lexical copied to clipboard

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

Open orelbn opened this issue 1 year ago • 3 comments

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 avatar Oct 25 '24 16:10 orelbn

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.

orelbn avatar Oct 25 '24 16:10 orelbn

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

hunxjunedo avatar Oct 27 '24 20:10 hunxjunedo

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

etrepum avatar Oct 27 '24 23:10 etrepum