fix: insertContent keeps marks when using plain text, fix #2406

This commit is contained in:
Philipp Kühn
2022-01-20 22:15:12 +01:00
parent 27983bf38d
commit d2427064ff

View File

@@ -53,6 +53,7 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
? { from: position, to: position }
: position
let isOnlyTextContent = true
let isOnlyBlockContent = true
const nodes = isFragment(content)
? content
@@ -62,6 +63,10 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
// check if added node is valid
node.check()
isOnlyTextContent = isOnlyTextContent
? node.isText && node.marks.length === 0
: false
isOnlyBlockContent = isOnlyBlockContent
? node.isBlock
: false
@@ -84,7 +89,13 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
}
}
tr.replaceWith(from, to, content)
// if there is only plain text we have to use `insertText`
// because this will keep the current marks
if (isOnlyTextContent) {
tr.insertText(value as string, from, to)
} else {
tr.replaceWith(from, to, content)
}
// set cursor at end of inserted content
if (options.updateSelection) {