editor: exit code block on arrow up

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-12-12 11:20:03 +05:00
parent 88ecb58153
commit 3c8c949e68

View File

@@ -425,6 +425,37 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
})
)
.run();
},
ArrowUp: ({ editor }) => {
if (!this.options.exitOnArrowUp) {
return false;
}
const { state } = editor;
const { selection } = state;
const { $anchor, empty, $from } = selection;
if (!empty || $anchor.parent.type !== this.type) {
return false;
}
const isAtStartOfNode = $from.parentOffset === 0;
if (!isAtStartOfNode) {
return false;
}
const before = $from.before();
if (before === undefined) {
return false;
}
const nodeBefore = state.doc.nodeAt(before);
if (nodeBefore) {
editor.commands.setNodeSelection($from.before());
return false;
}
return editor.commands.exitCode();
}
};
},