Skip to content

Commit

Permalink
fix(core): InputRules does not work for ranges containing multiple te…
Browse files Browse the repository at this point in the history
…xt nodes (#3205)

* fix: InputRules does not work for ranges containing multiple text nodes. #3071

* chore: rename `to` to `sliceEndPos`
  • Loading branch information
hamflx authored Sep 29, 2022
1 parent 539afce commit 2f9ba32
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/core/src/helpers/getTextContentFromNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { ResolvedPos } from 'prosemirror-model'
export const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {
let textBefore = ''

const sliceEndPos = $from.parentOffset

$from.parent.nodesBetween(
Math.max(0, $from.parentOffset - maxMatch),
$from.parentOffset,
Math.max(0, sliceEndPos - maxMatch),
sliceEndPos,
(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, sliceEndPos - pos))
},
)

Expand Down

0 comments on commit 2f9ba32

Please sign in to comment.