diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index 638c95e4f..5d9f66510 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -146,6 +146,37 @@ export const CodeBlock = Node.create({ .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() + }, } },