fix: Cannot exit code block with mod-enter shortcut with edit mode enabled
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user