fix(core): dont use selection for setContent replacement (#2934)

This commit is contained in:
Dominik
2022-07-06 12:59:16 +02:00
committed by GitHub
parent 8bc3986f17
commit 134a4bd1fb

View File

@@ -1,5 +1,4 @@
import { ParseOptions } from 'prosemirror-model' import { ParseOptions } from 'prosemirror-model'
import { TextSelection } from 'prosemirror-state'
import { createDocument } from '../helpers/createDocument' import { createDocument } from '../helpers/createDocument'
import { Content, RawCommands } from '../types' import { Content, RawCommands } from '../types'
@@ -22,11 +21,9 @@ declare module '@tiptap/core' {
export const setContent: RawCommands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => { export const setContent: RawCommands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
const { doc } = tr const { doc } = tr
const document = createDocument(content, editor.schema, parseOptions) const document = createDocument(content, editor.schema, parseOptions)
const selection = TextSelection.create(doc, 0, doc.content.size)
if (dispatch) { if (dispatch) {
tr.setSelection(selection) tr.replaceWith(0, doc.content.size, document)
.replaceSelectionWith(document, false)
.setMeta('preventUpdate', !emitUpdate) .setMeta('preventUpdate', !emitUpdate)
} }