@@ -25,9 +25,9 @@ function selectAdjacentLeaf(editor: Editor, direction: 'up' | 'down'): boolean {
2525/**
2626 * Editor-specific keyboard behavior layered on top of StarterKit's defaults:
2727 *
28- * - **Backspace** at the start of a block whose previous sibling is a horizontal rule deletes the
29- * rule. ProseMirror's default `joinBackward` can't cross a leaf node, so without this pressing
30- * Backspace below a divider is a confusing no-op.
28+ * - **Backspace** at the start of a heading reverts it to a paragraph; at the start of a block whose
29+ * previous sibling is a horizontal rule it deletes the rule (ProseMirror's default `joinBackward`
30+ * can't cross a leaf node, so without this pressing Backspace below a divider is a confusing no-op) .
3131 * - **Mod-A** inside a code block selects only that block's contents; pressing it again (when the
3232 * block is already fully selected) falls through to the default whole-document select-all, the
3333 * same scoped behavior as a code editor.
@@ -42,6 +42,11 @@ export const EditorKeymap = Extension.create({
4242 Backspace : ( { editor } ) => {
4343 const { selection, doc } = editor . state
4444 if ( ! selection . empty || selection . $from . parentOffset !== 0 ) return false
45+ // At the start of a heading, revert it to a paragraph (ProseMirror's default joins or
46+ // no-ops, stranding the heading style); a second Backspace then merges as usual.
47+ if ( selection . $from . parent . type . name === 'heading' ) {
48+ return editor . commands . setParagraph ( )
49+ }
4550 const blockStart = selection . $from . before ( selection . $from . depth )
4651 const nodeBefore = doc . resolve ( blockStart ) . nodeBefore
4752 if ( nodeBefore ?. type . name !== 'horizontalRule' ) return false
0 commit comments