Skip to content

Commit 07762fd

Browse files
committed
Fix: initialize undomanager for empty document
Signed-off-by: Benjamin Frueh <[email protected]>
1 parent 06100d2 commit 07762fd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/components/Editor.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,25 @@ export default defineComponent({
485485
this.idle = false
486486
},
487487
488+
initUndoManagerForEmptyDocument() {
489+
if (this.editor.state.doc.textContent.length > 0 || !this.editor.isEditable) {
490+
return
491+
}
492+
493+
if (!this.editor.commands.insertContent(' ')) {
494+
return
495+
}
496+
497+
this.editor.commands.deleteRange({ from: 0, to: 1 })
498+
499+
const undoManager = this.editor.state.plugins
500+
.map(p => p.getState?.(this.editor.state)?.undoManager)
501+
.find(um => um?.clear)
502+
undoManager?.clear()
503+
504+
this.dirty = false
505+
},
506+
488507
onOpened({ document, session, content, documentState, readOnly }) {
489508
this.document = document
490509
this.readOnly = readOnly
@@ -520,6 +539,7 @@ export default defineComponent({
520539
isRichEditor: this.isRichEditor,
521540
})
522541
}
542+
this.initUndoManagerForEmptyDocument()
523543
})
524544
this.updateUser(session)
525545
},

0 commit comments

Comments
 (0)