mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 11:45:15 +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 { from, to } = range
|
||||||
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
const { blockSeparator = '\n\n', textSerializers = {} } = options || {}
|
||||||
let text = ''
|
let text = ''
|
||||||
let separated = true
|
|
||||||
|
|
||||||
startNode.nodesBetween(from, to, (node, pos, parent, index) => {
|
startNode.nodesBetween(from, to, (node, pos, parent, index) => {
|
||||||
|
if (node.isBlock && pos > from) {
|
||||||
|
text += blockSeparator
|
||||||
|
}
|
||||||
|
|
||||||
const textSerializer = textSerializers?.[node.type.name]
|
const textSerializer = textSerializers?.[node.type.name]
|
||||||
|
|
||||||
if (textSerializer) {
|
if (textSerializer) {
|
||||||
if (node.isBlock && !separated) {
|
|
||||||
text += blockSeparator
|
|
||||||
separated = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
text += textSerializer({
|
text += textSerializer({
|
||||||
node,
|
node,
|
||||||
@ -39,10 +37,6 @@ export function getTextBetween(
|
|||||||
|
|
||||||
if (node.isText) {
|
if (node.isText) {
|
||||||
text += node?.text?.slice(Math.max(from, pos) - pos, to - pos) // eslint-disable-line
|
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