Skip to content

Commit 8a736a5

Browse files
authored
Merge pull request #689 from Harbour-Enterprises/har-10093_undo-redo-disabled
fix: undo/redo buttons are disabled in collaborative mode
2 parents a253b34 + ccf3478 commit 8a736a5

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/super-editor/src/components/toolbar/super-toolbar.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getQuickFormatList } from '@extensions/linked-styles/linked-styles.js';
1313
import { getAvailableColorOptions, makeColorOption, renderColorOptions } from './color-dropdown-helpers.js';
1414
import { isInTable } from '@helpers/isInTable.js';
1515
import { useToolbarItem } from '@components/toolbar/use-toolbar-item';
16+
import { yUndoPluginKey } from 'y-prosemirror';
1617

1718
/**
1819
* @typedef {Object} ToolbarConfig
@@ -800,8 +801,15 @@ export class SuperToolbar extends EventEmitter {
800801
*/
801802
#updateToolbarHistory() {
802803
if (!this.activeEditor) return;
803-
this.undoDepth = undoDepth(this.activeEditor.state);
804-
this.redoDepth = redoDepth(this.activeEditor.state);
804+
805+
if (this.activeEditor.options.ydoc) {
806+
const undoManager = yUndoPluginKey.getState(this.activeEditor.state)?.undoManager;
807+
this.undoDepth = undoManager?.undoStack.length || 0;
808+
this.redoDepth = undoManager?.redoStack.length || 0;
809+
} else {
810+
this.undoDepth = undoDepth(this.activeEditor.state);
811+
this.redoDepth = redoDepth(this.activeEditor.state);
812+
}
805813
}
806814

807815
/**

packages/super-editor/src/core/Editor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ export class Editor extends EventEmitter {
660660
if (!this.options.isNewFile) return;
661661
this.options.isNewFile = false;
662662
const doc = this.#generatePmData();
663-
const tr = this.state.tr.replaceWith(0, this.state.doc.content.size, doc);
663+
// hiding this transaction from history so it doesn't appear in undo stack
664+
const tr = this.state.tr.replaceWith(0, this.state.doc.content.size, doc).setMeta('addToHistory', false);
664665
this.view.dispatch(tr);
665666

666667
setTimeout(() => {

0 commit comments

Comments
 (0)