Skip to content

Commit cff9c03

Browse files
benjaminfruehjuliusknorr
authored andcommitted
Fix: initialize undomanager for empty document
Signed-off-by: Benjamin Frueh <[email protected]>
1 parent fbbbe6c commit cff9c03

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/components/Editor.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,28 @@ export default defineComponent({
485485
this.idle = false
486486
},
487487
488+
initUndoManagerForEmptyDocument() {
489+
if (
490+
this.editor.state.doc.textContent.length > 0
491+
|| !this.editor.isEditable
492+
) {
493+
return
494+
}
495+
496+
if (!this.editor.commands.insertContent(' ')) {
497+
return
498+
}
499+
500+
this.editor.commands.deleteRange({ from: 0, to: 1 })
501+
502+
const undoManager = this.editor.state.plugins
503+
.map((p) => p.getState?.(this.editor.state)?.undoManager)
504+
.find((um) => um?.clear)
505+
undoManager?.clear()
506+
507+
this.dirty = false
508+
},
509+
488510
onOpened({ document, session, content, documentState, readOnly }) {
489511
this.document = document
490512
this.readOnly = readOnly
@@ -520,6 +542,7 @@ export default defineComponent({
520542
isRichEditor: this.isRichEditor,
521543
})
522544
}
545+
this.initUndoManagerForEmptyDocument()
523546
})
524547
this.updateUser(session)
525548
},

0 commit comments

Comments
 (0)