From ffafff9e365f9636fae4a67bb825d49b7d95cb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Thu, 16 Dec 2021 15:16:08 +0100 Subject: [PATCH] feat: escape code blocks on arrow down, fix #1204 --- .../extension-code-block/src/code-block.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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() + }, } },