Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
orelbn opened this issue Oct 25, 2024 · 3 comments

Comments

@orelbn
Copy link

orelbn commented Oct 25, 2024

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

Screen.Recording.2024-10-25.at.9.18.08.AM.mov

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
Copy link
Author

orelbn commented Oct 25, 2024

I believe it has to do with this function.

/**
* Attempts to "intelligently" insert an arbitrary list of Lexical nodes into the EditorState at the
* current Selection according to a set of heuristics that determine how surrounding nodes
* should be changed, replaced, or moved to accommodate the incoming ones.
*
* @param nodes - the nodes to insert
*/
insertNodes(nodes: Array<LexicalNode>): void {

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

@orelbn orelbn changed the title Bug: Pastes starting over content starting with an empty paragraph appends instead of replace Bug: Pastes over content starting with an empty node appends instead of replace Oct 25, 2024
@orelbn orelbn changed the title Bug: Pastes over content starting with an empty node appends instead of replace Bug: Pasting over content starting with an empty node appends instead of replace Oct 25, 2024
@hunxjunedo
Copy link

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

@etrepum
Copy link
Collaborator

etrepum commented Oct 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants