From 9b811c999d7db3b8b49bd9d0ac74b43c7565905b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 5 Aug 2023 19:45:54 -0400 Subject: [PATCH] fix: Cannot exit code block with mod-enter shortcut with edit mode enabled --- shared/editor/queries/isInCode.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/shared/editor/queries/isInCode.ts b/shared/editor/queries/isInCode.ts index 329cb7d68..70c7706df 100644 --- a/shared/editor/queries/isInCode.ts +++ b/shared/editor/queries/isInCode.ts @@ -1,15 +1,30 @@ import { EditorState } from "prosemirror-state"; import isMarkActive from "./isMarkActive"; +/** + * Returns true if the selection is inside a code block or code mark. + * + * @param state The editor state. + * @returns True if the selection is inside a code block or code mark. + */ export default function isInCode(state: EditorState): boolean { - if (state.schema.nodes.code_block) { + const { nodes, marks } = state.schema; + + if (nodes.code_block || nodes.code_fence) { const $head = state.selection.$head; for (let d = $head.depth; d > 0; d--) { - if ($head.node(d).type === state.schema.nodes.code_block) { + if (nodes.code_block && $head.node(d).type === nodes.code_block) { + return true; + } + if (nodes.code_fence && $head.node(d).type === nodes.code_fence) { return true; } } } - return isMarkActive(state.schema.marks.code_inline)(state); + if (marks.code_inline) { + return isMarkActive(marks.code_inline)(state); + } + + return false; }