From 305ebc490f70d24aa6a22e3f66aa6c4e140a3d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 11 Jul 2019 23:45:22 +0200 Subject: [PATCH] dispatch event for setContent instead of creating a new state --- packages/tiptap/src/Editor.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index 7f115d831..1d19683c0 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -328,7 +328,7 @@ export default class Editor extends Emitter { transaction, }) - if (!transaction.docChanged) { + if (!transaction.docChanged || transaction.getMeta('preventUpdate')) { return } @@ -395,17 +395,15 @@ export default class Editor extends Emitter { } setContent(content = {}, emitUpdate = false, parseOptions) { - const newState = EditorState.create({ - schema: this.state.schema, - doc: this.createDocument(content, parseOptions), - plugins: this.state.plugins, - }) + const { doc, tr } = this.state + const document = this.createDocument(content, parseOptions) + const selection = TextSelection.create(doc, 0, doc.content.size) + const transaction = tr + .setSelection(selection) + .replaceSelectionWith(document, false) + .setMeta('preventUpdate', !emitUpdate) - this.view.updateState(newState) - - if (emitUpdate) { - this.emitUpdate() - } + this.view.dispatch(transaction) } clearContent(emitUpdate = false) {