Skip to content

Commit

Permalink
fix: InputRules does not work for ranges containing multiple text nod…
Browse files Browse the repository at this point in the history
  • Loading branch information
hamflx committed Sep 16, 2022
1 parent c7b7a16 commit 417ac55
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/helpers/getTextContentFromNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { ResolvedPos } from 'prosemirror-model'
export const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {
let textBefore = ''

const to = $from.parentOffset
$from.parent.nodesBetween(
Math.max(0, $from.parentOffset - maxMatch),
$from.parentOffset,
Math.max(0, to - maxMatch),
to,
(node, pos, parent, index) => {
textBefore += node.type.spec.toText?.({
const chunk = node.type.spec.toText?.({
node, pos, parent, index,
}) || $from.nodeBefore?.text || '%leaf%'
}) || node.textContent || '%leaf%'
textBefore += chunk.slice(0, Math.max(0, to - pos))
},
)

Expand Down

0 comments on commit 417ac55

Please sign in to comment.