Skip to content

Commit

Permalink
Fix getTextBetween (#5055)
Browse files Browse the repository at this point in the history
  • Loading branch information
hivokas committed May 10, 2024
1 parent baff4af commit edceec4
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions packages/core/src/helpers/getTextBetween.ts
Expand Up @@ -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,
Expand All @@ -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
}
})

Expand Down

0 comments on commit edceec4

Please sign in to comment.