Files
outline/shared/editor/queries/getCurrentBlock.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

27 lines
699 B
TypeScript

import type { Node } from "prosemirror-model";
import type { EditorState } from "prosemirror-state";
/**
* Gets the current block node that contains the selection
* @param state The editor state
* @returns The current block node and its position, or undefined if not found
*/
export function getCurrentBlock(
state: EditorState
): [Node, number] | undefined {
const { $head } = state.selection;
// Walk up the tree to find the first block node
for (let d = $head.depth; d >= 0; d--) {
const node = $head.node(d);
const pos = $head.before(d);
if (node.isBlock && d > 0) {
// Don't return the document itself
return [node, pos];
}
}
return undefined;
}