Bug: List: delete the leading ListItemNode will also delete the previous…
- User
Bug: List: delete the leading ListItemNode will also delete the previous DecoratorBlockNode Lexical version: 0.12.2
Steps To Reproduce
- Open the playground at https://playground.lexical.dev/
- Append a
DecoratorBlockNodeto the document, for example, aTweetNode - Insert a list after the
DecoratorBlockNode - Delete the first list item, and the previous
DecoratorBlockNodewill also be removed
https://github.com/facebook/lexical/assets/6022672/2ccbc2a0-af27-4d3f-a244-804f43249fec
The current behavior
Both the
ListNodeand the previousDecoratorBlockNodeare deleted.The expected behavior
Only
ListNodewould be deleted. (I will be more than happy to see theListNodebe replaced by aParagraphNodeif possible! That's the default behavior in other editors.)Interface
No new interfaces are introduced.
- Assistant
I'll investigate how list deletion interacts with preceding
DecoratorBlockNodeinstances and trace the delete/backspace handling path. - Assistant
I'll add a failing test that reproduces the bug, then trace the deletion path.
- Assistant
The issue is
deleteCharacterremoves the preceding decorator beforecollapseAtStartcan run on the list item. I'll call$collapseAtStartearlier in that path. - Assistant
Fixed. Backspace at the start of the first list item was deleting the preceding
DecoratorBlockNodeinstead of only collapsing the list.Root cause
When backspacing at offset 0 with no text before the cursor,
deleteCharacter()walks backward and hits the previousDecoratorBlockNodefirst. That path removes the decorator and returns early:1847:1853:packages/lexical/src/LexicalSelection.ts} else { // When the anchor is not an empty element then the // adjacent decorator is removed caret.origin.remove(); } // always stop when a decorator is encountered return;— which uses to replace the list with a — never ran.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.