fix: remove codeblock when at start of document, fix #262

This commit is contained in:
Philipp Kühn
2021-04-11 18:29:03 +02:00
parent 65ee85d6cc
commit 92f6ea25cc

View File

@@ -101,6 +101,22 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
addKeyboardShortcuts() { addKeyboardShortcuts() {
return { return {
'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(), 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),
// remove code block when at start of document or code block is empty
Backspace: state => {
const { empty, $anchor } = state.selection
const isAtStart = $anchor.pos === 1
if (!empty || $anchor.parent.type.name !== 'codeBlock') {
return false
}
if (isAtStart || !$anchor.parent.textContent.length) {
return this.editor.commands.clearNodes()
}
return false
},
} }
}, },