mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 11:49:02 +08:00
fix(core): InputRules does not work for ranges containing multiple text nodes (#3205)
* fix: InputRules does not work for ranges containing multiple text nodes. #3071 * chore: rename `to` to `sliceEndPos`
This commit is contained in:
parent
539afce4fd
commit
2f9ba324a0
@ -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))
|
||||
},
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user