fix: Exit the list on Backspace in an empty list item in Docs#339
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a design document and README index entry, implements an early-return branch in ChangesBackspace empty list-item exit design & implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Design note for issue wafflebase#338. Backspace at the start of an empty list item is a no-op (when it is the first block) or merges into the previous block, instead of exiting the list. Enter already handles this in Doc.splitBlock (empty list-item -> paragraph); Doc.deleteBackward is missing the same branch, and the blockIndex<=0 guard returns before any list handling, which is why the empty-document case does nothing. The note proposes mirroring splitBlock's branch in deleteBackward, placed before the blockIndex<=0 guard so it also fires for the first/only block. Design-note-first; implementation to follow on this branch.
9133984 to
ce55f31
Compare
Backspace at offset 0 of an empty list-item now converts it to a paragraph, exiting the list. Previously it was a no-op when the item was the first/only block and merged into the previous block otherwise. This mirrors the branch Doc.splitBlock already has for Enter, added to Doc.deleteBackward before the blockIndex<=0 guard so it also fires for the first/only block. Closes wafflebase#338.
hackerwins
left a comment
There was a problem hiding this comment.
Thanks for your contribution.
Summary
Design note for issue #338: pressing Backspace at the start of an empty list
item should exit the list (convert it back to a paragraph), matching what Enter
already does. Today it does not — it is a no-op when the list item is the first
block (e.g. an empty document with numbering), or it merges into the previous
block otherwise.
This is the design-note-first step (no code yet) — opening for direction
before implementing. Implementation will follow on this same branch.
Why
The two paths live in
packages/docs/src/model/document.ts. Enter →splitBlock()has an early branch that converts an emptylist-itemto aparagraphto exit the list. Backspace →deleteBackward()has no suchbranch: at
offset 0it goes straight to "merge with previous", and theif (blockIndex <= 0) return posguard returns first when the item is the onlyblock — which is exactly why the empty-document case does nothing.
The note proposes mirroring
splitBlock's branch indeleteBackward, placedafter the
offset > 0return and before theblockIndex <= 0guard so italso fires for the first/only block. It flags nested-list outdent (
listLevel > 0)as a non-goal / open question (matching Enter's simpler behavior for now).
Test plan
No code changes yet — design note only. The note's Test Plan covers the
implementation that will follow (mirrors the existing
splitBlockempty-list-itemtest in
packages/docs/test/model/document.test.ts): empty list item as firstblock, as non-first block, non-empty list item unchanged, mid-text delete
unchanged.
Notes for Reviewers
AI tools assisted with this PR: the code investigation and the note draft were
produced with Claude Code (Claude Opus 4.8). I reviewed the root-cause analysis
and every line of the note.
Fixes #338.
Summary by CodeRabbit
Bug Fixes
Documentation
Tests