use tr.replaceRangeWith instead of tr.insert for insertContent command

This commit is contained in:
Philipp Kühn 2021-05-05 14:50:27 +02:00
parent e2756aab5f
commit 12b6f0e4f7

View File

@ -20,15 +20,11 @@ declare module '@tiptap/core' {
export const insertContentAt: RawCommands['insertContentAt'] = (range, value) => ({ tr, dispatch, editor }) => {
if (dispatch) {
if (range.from !== range.to) {
tr.deleteRange(range.from, range.to)
}
const content = createNodeFromContent(value, editor.schema)
tr.insert(range.from, content)
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
tr.scrollIntoView()
// @ts-ignore
tr.replaceRangeWith(range.from, range.to, content)
selectionToInsertionEnd(tr, tr.steps.length - 1, 1)
}
return true