Skip to content

Commit 55860f6

Browse files
committed
improvement(file-viewer): Backspace at start of a heading reverts it to a paragraph
Notion-style: ProseMirror's default joins or no-ops at a heading boundary, stranding the heading style. A second Backspace then merges as usual.
1 parent b7d87c8 commit 55860f6

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/keymap.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)