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.)Interface
No new interfaces are introduced.
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 start by exploring the repository structure and understanding the bug related to deleting ListItemNodes near DecoratorBlockNodes.
- Assistant
Let me look at the packages structure and search for relevant code related to list deletion.
- Assistant
rg is not available, let me use grep instead.
- Assistant
Let me search for list-related deletion and backspace handling.
- Assistant
Let me look at the ListItemNode more carefully, and also search for how backspace is handled when at the start of a list.
- Assistant
Let me look at collapseAtStart in ListItemNode and how rich-text handles backspace.
- Assistant
Let me look at collapseAtStart in ListItemNode and ParagraphNode, and the deleteCharacter flow.
- Assistant
Let me examine deleteCharacter and how it interacts with previous siblings.
- Assistant
Let me read the deleteCharacter function carefully.
- Assistant
Found relevant decorator handling - let me read more of this section.
- Assistant
Let me continue reading the collapseAtStart path.
- Assistant
Let me examine DecoratorBlockNode properties and look for related tests or git history for this bug.
- Assistant
There's no existing fix for this. Let me look at git history related to decorator deletion become list. Also let me check version 0.12.2 behavior vs current, and try to write a test to reproduce.
- Assistant
Let me read the decorator node defaults.
- Assistant
Let me look at tests related to deleteCharacter and decorator.
- Assistant
Let me look for tests specifically about backspace with block decorators and empty paragraphs, as the code comment mentioned that path.
- Assistant
Let me try to find list + decorator tests and also check if there's a GitHub issue or PR about this.
- Assistant
Let me examine existing tests and how TestDecoratorNode is set硗up, then try to reproduce the bug.
- Assistant
Let me find the test utils.
- Assistant
Hmm grep didn't find it. Let me try again.
- Assistant
Let me read the test decorator node.
- Assistant
I'll look at an existing unit test structure and then write a temporary reproduction script.
- Assistant
Let me also check recent related changes and how initializeUnitTest works with list nodes.
- Assistant
Let me check how to run tests and write a reproduction.
- Assistant
I'll create a temporary test to reproduce the bug.
- Assistant
Now run the reproduction test.
- Assistant
The test timed out — let me try running vitest directly with a filter.
- Assistant
Reproduced the bug: backspace at the start of a filled first list item deletes the decorator. Let me debug the removeText/caret path.
- Assistant
Let me add detailed debugging to the reproduction test.
- Assistant
Interesting — I need to check whether the same bug occurs with a normal paragraph after a decorator.
- Assistant
Let me rewrite the test file properly.
- Assistant
Let me read ParagraphNode.collapseAtStart and related $collapseAroundDecorator handling.
- Assistant
Let me carefully understand how caret iteration walks upstream from a list item.
- Assistant
Let me read iterNodeCarets and related logic.
- Assistant
Let me understand SiblingCaret and pointing at previous nodes.
- Assistant
Let me map out the iteration for our case more carefully by instrumenting or reading carefully.
- Assistant
Letme. read $getAdjacentChildCaret
- Assistant
Let meadd temporary logging inside deleteCharacter to Classroom see the caret walk.
- Assistant
Let me check getAdjacentCaret.
- Assistant
getAdjacentCaret(): null | SiblingCaret<LexicalNode, D> { - Assistant
Let me read the $collapseAtStart helper carefully.
- Assistant
Let me check the git history for this decorator deletion logic.
- Assistant
Let me look at that PR and associated tests.
- Assistant
Let me look at the unit tests added and HorizontalRule e2e which is a block decorator-like node.
- Assistant
Let me look at HorizontalRule e2e tests related to deletion.
- Assistant
Let me read those tests around 400-540.
- Assistant
Look at earlier part of HRtests for list after HR - lines around 350-400 and the empty paragraph delete test.
- Assistant
Let me look at line 490: Can delete empty paragraph after a horizontal rule
- Assistant
Looking at what happens with a filled paragraph after a decorator currently - backspace deletes the decorator. Is that considered correct? I see the issue now. The bug is specifically when the first list item has content (not empty), deleting it causes the preceding decorator to be removed along with the list. That's unexpected behavior.
Let me think about how to fix this properly. The core problem seems to be in how Lexical handles deletion of list items when they have content, and how it interacts with previous sibling blocks like decorators.
- Assistant
Let me search for more tests about backspace after block decorators with text.
- Assistant
Let me also look at the previously intact CodeBlock deletion tests.
- Assistant
Let me look at how HorizontalRule is implemented and if there are relevant unit tests near selection.
- Assistant
Let me duplicate of the base HR node.
- Assistant
Let me find the base HorizontalRuleNode in extension.
- Assistant
I understand the bug. When backspacing at the start of a filled list item after a block decorator, the code deletes the decorator instead of running
collapseAtStart(which converts the list item to a paragraph). I'll fix that path. - Assistant
The edit went to the wrong file. Let me undo that and apply the fix to LexicalSelection.ts.
- Assistant
Now apply the fix to LexicalSelection.ts.
- Assistant
Now let me update the reproduction test to verify the fix comprehensively.
- Assistant
All reproduction tests pass. Let me verify heading/quote cases and run related unit tests.
- Assistant
Let me also verify[:, heading after decorator and list-after-paragraph still work correctly.
- Assistant
I introduced typos — let me rewrite the test cleanly.
- Assistant
There's still a small typo to fix.
- Assistant
Heading didn't collapse — let me check HeadingNode.collapseAtStart.
- Assistant
HeadingNode.collapseAtStartreturns true even when it does nothing for non-empty headings. I'll fix that so our new path doesn't noop incorrectly. - Assistant
Heading intentionally no-ops while returning true for non-empty content — that's fine. Our path keeps the decorator. Let me clean up the temp test and run a broader test suite.
- Assistant
All related tests pass. Let me verify the final diff and run a broader suite covering selection/caret behavior.
- Assistant
All 582 unit tests pass. Cleaning up and submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.