mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 19:29:02 +08:00
dispatch event for setContent instead of creating a new state
This commit is contained in:
parent
8c5926e7c7
commit
305ebc490f
@ -328,7 +328,7 @@ export default class Editor extends Emitter {
|
|||||||
transaction,
|
transaction,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!transaction.docChanged) {
|
if (!transaction.docChanged || transaction.getMeta('preventUpdate')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,17 +395,15 @@ export default class Editor extends Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContent(content = {}, emitUpdate = false, parseOptions) {
|
setContent(content = {}, emitUpdate = false, parseOptions) {
|
||||||
const newState = EditorState.create({
|
const { doc, tr } = this.state
|
||||||
schema: this.state.schema,
|
const document = this.createDocument(content, parseOptions)
|
||||||
doc: this.createDocument(content, parseOptions),
|
const selection = TextSelection.create(doc, 0, doc.content.size)
|
||||||
plugins: this.state.plugins,
|
const transaction = tr
|
||||||
})
|
.setSelection(selection)
|
||||||
|
.replaceSelectionWith(document, false)
|
||||||
|
.setMeta('preventUpdate', !emitUpdate)
|
||||||
|
|
||||||
this.view.updateState(newState)
|
this.view.dispatch(transaction)
|
||||||
|
|
||||||
if (emitUpdate) {
|
|
||||||
this.emitUpdate()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearContent(emitUpdate = false) {
|
clearContent(emitUpdate = false) {
|
||||||
|
Loading…
Reference in New Issue
Block a user