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 how list deletion and DecoratorBlockNodes interact.
- Assistant
Let me search for related code and any existing issues or PRs about this bug.
- Assistant
rg is not available, let me use grep instead.
- Assistant
Let me look at list item deletion logic and search for related delete handling.
- Assistant
The issue is likely in
collapseAtStarton ListItemNode. Let me inspect that and the surrounding selection logic. - Assistant
Let me examine the selection delete/collapse logic that may remove the previous block.
- Assistant
Let me look at the
$collapseAtStartfunction and also the removeText logic when selection spans decorators. - Assistant
Let me search git history and code for similar decorator/list deletion bugs.
- Assistant
Let me read the full deleteCharacter method and how selection interactswith block decorators.
- Assistant
Let me read the start of deleteCharacter to understand the full flow.
- Assistant
Let me understand the caret iteration and look for existing tests related to this bug.
- Assistant
Let me look at git log for fixes related to decorator delete near empty blocks, and also search CHANGELOG and github issues.
- Assistant
I'll look at related deleteCharacter tests and try to reproduce the bug.
- Assistant
Hmm. Let me look for TestDecoratorNode Utility and also how to create block decorators in tests.
- Assistant
Let me study the caret range iteration and reproduce with a focused test script.
- Assistant
Let me write a quick reproduction script to understand the exact behavior. First I'll check the test utilities.
- Assistant
Let me find the utils path
- Assistant
I'll create a temporary reproduction script and run it.
- Assistant
Let me create a temp test file to reproduce
- Assistant
I need to put the test in the right place for vitest to pick it up. Let me put it in packages/lexical/src/tests/unit/
- Assistant
Good. Now let's run the test.
- Assistant
It timed out. Let me try running vitest more directly with a longer timeout... maybe installing or something is slow.
- Assistant
$isListNode is not from 'lexical', it's from '@lexical/list'. Let me fix the test.
- Assistant
The bug is clearer now. Let me also check paragraph-after-decorator behavior and the empty-list case more carefully.
- Assistant
Let me examine PR #7248 and the intended behavior when collapsing at a decorator boundary.
- Assistant
Let me look at the empty list item result more carefully - the first test output was truncated. Also let me look at HorizontalRule since HR is like a block decorator.
- Assistant
Let me also look at the empty list item console output by running just that, and check git blame for the decorator removal logic.
- Assistant
Let me read the caret iteration and understand the full delete flow when state is set.
- Assistant
$extendCaretToRangecreates a range from caret to the end. Let me check that. - Assistant
I'll debug the caret walk for the list + decorator scenario.
- Assistant
Let me check paragrafo and heading collapseAtStart behavior.
- Assistant
Checking how selectPrevious works on a decorator and reviewing existing selection tests.
- Assistant
Let me read selectPrevious
- Assistant
I'll compare caret walks for empty paragraph and empty list with those for text cases.
- Assistant
Let me write the debug test cleanly with a simple approach.
- Assistant
No python. Let me kullan use node.
- Assistant
I understand the bug: when the caret walks through a structural
Listparent before hitting a block decorator, it deletes the decorator instead of collapsing the list item. I'll implement the fix. - Assistant
Implementing the fix in the decorator-handling branch of
deleteCharacter. - Assistant
Now I'll update the repro test to verify the fix across the main cases.
- Assistant
All repro cases pass. Running existing selection and list tests to check for regressions.
- Assistant
All those passed. Let me also run caret tests and search for related deleteCharacter tests.
- Assistant
Removing the temporary test file and verifying TypeScript is happy.
- Assistant
There are still some typos. Let me write a clean edge test.
- Assistant
Typo in the path.
- Assistant
Edge cases look good. Cleaning up the temporary test and reviewing the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.