mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-23 19:19:03 +08:00
Fix getTextBetween (#5055)
This commit is contained in:
parent
baff4af39e
commit
edceec4898
@ -13,17 +13,15 @@ export function getTextBetween(
|
||||
const { from, to } = range
|
||||
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
||||
let text = ''
|
||||
let separated = true
|
||||
|
||||
startNode.nodesBetween(from, to, (node, pos, parent, index) => {
|
||||
if (node.isBlock && pos > from) {
|
||||
text += blockSeparator
|
||||
}
|
||||
|
||||
const textSerializer = textSerializers?.[node.type.name]
|
||||
|
||||
if (textSerializer) {
|
||||
if (node.isBlock && !separated) {
|
||||
text += blockSeparator
|
||||
separated = true
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
text += textSerializer({
|
||||
node,
|
||||
@ -39,10 +37,6 @@ export function getTextBetween(
|
||||
|
||||
if (node.isText) {
|
||||
text += node?.text?.slice(Math.max(from, pos) - pos, to - pos) // eslint-disable-line
|
||||
separated = false
|
||||
} else if (node.isBlock && !separated) {
|
||||
text += blockSeparator
|
||||
separated = true
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user