Files
outline/shared/editor/queries/getParentListItem.ts
2024-06-08 21:51:52 -04:00

13 lines
401 B
TypeScript

import { Node } from "prosemirror-model";
import { EditorState } from "prosemirror-state";
export function getParentListItem(state: EditorState): [Node, number] | void {
const $head = state.selection.$head;
for (let d = $head.depth; d > 0; d--) {
const node = $head.node(d);
if (["list_item", "checkbox_item"].includes(node.type.name)) {
return [node, $head.before(d)];
}
}
}