mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
editor: exit code block on arrow up
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user