feat: escape code blocks on arrow down, fix #1204

This commit is contained in:
Philipp Kühn 2021-12-16 15:16:08 +01:00
parent 44ccba2b42
commit ffafff9e36

View File

@ -146,6 +146,37 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
.exitCode()
.run()
},
// escape node on arrow down
ArrowDown: ({ editor }) => {
const { state } = editor
const { selection, doc } = state
const { $from, empty } = selection
if (!empty || $from.parent.type !== this.type) {
return false
}
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2
if (!isAtEnd) {
return false
}
const after = $from.after()
if (after === undefined) {
return false
}
const nodeAfter = doc.nodeAt(after)
if (nodeAfter) {
return false
}
return editor.commands.exitCode()
},
}
},