ISSUE DESCRIPTION Bug: List: delete the leading ListItemNode will also delete the…
- User
ISSUE DESCRIPTION
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.)ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I’ll trace list deletion and decorator-block handling, identify the structural normalization path that removes the previous sibling, then implement the narrowest fix and run the relevant existing tests. I’ll also inspect repository status and conventions before editing.
- Assistant
rgis unavailable in this environment, so I’ll usegrep/findinstead. The working tree is clean, and I’m narrowing the search to list package transforms plus core editor deletion/normalization code. - Assistant
The relevant path is backwards deletion at an element boundary.
ListItemNodealready converts a solitary top-level list to a paragraph when it receives the collapse callback, but the callback traversal can start on theListNodeitself. Because the list has a previousDecoratorBlockNode, traversal stops before reaching the list item, and generic removal then cascades incorrectly. I’ll makeListNodehandle this boundary explicitly, preserving the decorator and remapping element-anchored selection points. - Assistant
The change is in place. It handles only a solitary empty list item, preserves nested-list behavior, and otherwise leaves normal list deletion untouched. I’ll now run formatting via the repository-local binary if available and execute the list package’s existing unit tests/type checks without modifying tests.
- Assistant
TypeScript compilation and formatting checks pass. The focused Vitest invocation is blocked by this checkout’s test setup selecting the
benchproject without a DOM (document is not defined); this is environmental and occurs broadly in existing tests, not from the change. I’m making one final cleanup so nested empty lists retain their established “remove nested list and select parent item” behavior rather than using an unreachable parent-type branch.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.