mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-07 03:48:15 +08:00
8c6751f0c6
* chore: add precommit hook for eslint fixes, fix linting issues * chore: add eslint import sort plugin
24 lines
531 B
TypeScript
24 lines
531 B
TypeScript
import { Node as ProseMirrorNode, ResolvedPos } from 'prosemirror-model'
|
|
|
|
import { Predicate } from '../types'
|
|
|
|
export function findParentNodeClosestToPos($pos: ResolvedPos, predicate: Predicate): ({
|
|
pos: number,
|
|
start: number,
|
|
depth: number,
|
|
node: ProseMirrorNode,
|
|
} | undefined) {
|
|
for (let i = $pos.depth; i > 0; i -= 1) {
|
|
const node = $pos.node(i)
|
|
|
|
if (predicate(node)) {
|
|
return {
|
|
pos: i > 0 ? $pos.before(i) : 0,
|
|
start: $pos.start(i),
|
|
depth: i,
|
|
node,
|
|
}
|
|
}
|
|
}
|
|
}
|