mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 00:27:49 +08:00
21 lines
543 B
TypeScript
21 lines
543 B
TypeScript
|
import { Node as ProseMirrorNode } from 'prosemirror-model'
|
||
|
import { Predicate, Range, NodeWithPos } from '../types'
|
||
|
|
||
|
/**
|
||
|
* Same as `findChildren` but searches only within a `range`.
|
||
|
*/
|
||
|
export default function findChildrenInRange(node: ProseMirrorNode, range: Range, predicate: Predicate): NodeWithPos[] {
|
||
|
const nodesWithPos: NodeWithPos[] = []
|
||
|
|
||
|
node.nodesBetween(range.from, range.to, (child, pos) => {
|
||
|
if (predicate(child)) {
|
||
|
nodesWithPos.push({
|
||
|
node: child,
|
||
|
pos,
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return nodesWithPos
|
||
|
}
|