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: when deleting consecutive DecoratorNodes, sometimes two are deleted at once #7319

Open
iansjk opened this issue Mar 12, 2025 · 1 comment · May be fixed by #7323
Open

Bug: when deleting consecutive DecoratorNodes, sometimes two are deleted at once #7319

iansjk opened this issue Mar 12, 2025 · 1 comment · May be fixed by #7323
Labels
core Reconciler, DOM, Selection, Node, Events, Composition decorators playground selection

Comments

@iansjk
Copy link

iansjk commented Mar 12, 2025

If a DecoratorNode is selected and I press Backspace, if there are two or more DecoratorNodes in a row, two of them are deleted at once.

Lexical version: 0.27.0

Steps To Reproduce

  1. Go to the Lexical Playground
  2. Insert a Horizontal Rule
  3. Press left arrow so that it's selected
  4. Copy it
  5. Press right arrow to deselect the hr
  6. Paste two times (for a total of 3 hrs)
  7. This should result in this state:
 root
  ├ (95) paragraph 
  ├ (96) horizontalrule 
  ├ (98) horizontalrule 
  └ (100) horizontalrule 
  1. Now select the bottommost horizontal rule
  • As an aside, pressing left arrow from the bottom of the editor seems to select the center hr at first
  1. Press backspace
  2. Only one should be deleted, but instead two are deleted, leaving the topmost one

This also occurs with pressing the Delete key when selecting either the top or middle hr; the next two hrs are deleted.

The current behavior

Two hrs are deleted at a time in the case described above

The expected behavior

Only one hr is deleted

Impact of fix

I pointed to the playground and used hrs to illustrate the example, but we're using custom DecoratorNodes in our application (that use the same $onDelete logic as LexicalHorizontalRuleNode) and this leads to surprising behavior for users when multiple are deleted at once. In the case of just two DecoratorNodes back to back, there is a workaround by selecting just one and either pressing Delete or Backspace to force a single node at the edge to be deleted, but we wouldn't expect users to be aware of how to do that.

@etrepum etrepum added core Reconciler, DOM, Selection, Node, Events, Composition decorators selection labels Mar 12, 2025
@etrepum
Copy link
Collaborator

etrepum commented Mar 12, 2025

This is mostly because of the $onDelete handlers for each of the DecoratorNodes that are added to the playground to handle NodeSelection deletion (incorrectly). They delete the selected node but return false and don't preventDefault so the nodes get deleted and then the browser also handles it which ends up deleting two nodes if it started with a NodeSelection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Reconciler, DOM, Selection, Node, Events, Composition decorators playground selection
Projects
None yet
2 participants