feat: delete empty section on backspace#3180
Conversation
Add keyboard shortcut handler to the Section node that deletes empty sections when pressing Backspace: - When cursor is inside an empty section at its start position, the entire section is removed (replaced with a plain paragraph if it's the only child of its parent) - When cursor is right after an empty section (previous sibling), that empty section is deleted This follows the same pattern used by ColumnsColumn for handling backspace deletion of structural nodes. Co-authored-by: Gabriel Miranda <gabrielmfern@outlook.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
commit: |
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
- User-facing behavior change: in
packages/editor/src/extensions/section.tsxBackspace won’t remove an empty section when the caret is in its first child, which could frustrate normal editing flows. - Given the medium-high severity and direct UX impact, there’s some regression risk despite being a localized change.
- Pay close attention to
packages/editor/src/extensions/section.tsx- the start-position check blocks Backspace deletion in a common caret position.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/editor/src/extensions/section.tsx">
<violation number="1" location="packages/editor/src/extensions/section.tsx:61">
P1: The start-position check is too strict, so Backspace won’t delete an empty section when the caret is in its first child block (the normal cursor position).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The previous check compared $from.pos against $from.start(sectionDepth), but the cursor is typically nested inside a child paragraph within the section, making the position offset by the nesting depth. Now we check $from.parentOffset === 0 (cursor at start of innermost block) and $from.index(d) === 0 for each level from section down (cursor is in the first child at every nesting level). Co-authored-by: Gabriel Miranda <gabrielmfern@outlook.com>
Summary
Adds a
Backspacekeyboard shortcut handler to the Section editor node so that pressing backspace deletes an empty section.Behavior
How it works
A section is considered "empty" when it has no text content and its content size is only the structural overhead of its child nodes (e.g., a single empty paragraph).
This follows the same pattern established by
ColumnsColumnincolumns.tsxfor handling backspace deletion of structural nodes.Changes
packages/editor/src/extensions/section.tsx— AddedaddKeyboardShortcuts()withBackspacehandler andisSectionEmpty()helper functionSlack Thread
Summary by cubic
Adds a Backspace shortcut to delete empty section nodes for cleaner documents. Also fixes the start-position check so deletion works inside nested blocks; if the section is the only child, it’s replaced with a plain paragraph.
Written for commit 2a6a6b3. Summary will update on new commits.