refactoring

This commit is contained in:
Philipp Kühn
2021-04-02 23:53:04 +02:00
parent dd505d2773
commit 6757813fd0
3 changed files with 29 additions and 27 deletions

View File

@@ -0,0 +1,22 @@
import { Node as ProseMirrorNode } from 'prosemirror-model'
import { Predicate } from '../types'
type NodeWithPos = {
node: ProseMirrorNode,
pos: number,
}
export default function findChildren(node: ProseMirrorNode, predicate: Predicate): NodeWithPos[] {
const nodesWithPos: NodeWithPos[] = []
node.descendants((child, pos) => {
if (predicate(child)) {
nodesWithPos.push({
node: child,
pos,
})
}
})
return nodesWithPos
}