style: move node text content into helper function

This commit is contained in:
Dominik Biedebach
2022-05-20 17:10:30 +02:00
committed by Dominik
parent 30c39c94c9
commit 0597e474af
4 changed files with 31 additions and 29 deletions

View File

@@ -0,0 +1,17 @@
import { ResolvedPos } from 'prosemirror-model'
export const getTextContentFromNodes = ($from: ResolvedPos<any>, maxMatch = 500) => {
let textBefore = ''
$from.parent.nodesBetween(
Math.max(0, $from.parentOffset - maxMatch),
$from.parentOffset,
(node, pos, parent, index) => {
textBefore += node.type.spec.toText?.({
node, pos, parent, index,
}) || node.textContent || '%leaf%'
},
)
return textBefore
}