Fix getTextBetween (#5055)

This commit is contained in:
Illia Sakovich 2024-05-10 04:51:22 +04:00 committed by GitHub
parent baff4af39e
commit edceec4898
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}
})