mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Disable undo/redo in detached formula editor
Summary: Undo and redo were causing errors to be thrown while the editor was detached. In the interest of time, we'll disable undo/redo until we have a chance to look at whether we can support it in the editor. Test Plan: Manual. Reviewers: JakubSerafin Reviewed By: JakubSerafin Differential Revision: https://phab.getgrist.com/D3959
This commit is contained in:
@@ -25,7 +25,7 @@ export interface IUndoState {
|
||||
* position in this stack. Undo and redo actions are generated and sent to the server here.
|
||||
*/
|
||||
export class UndoStack extends dispose.Disposable {
|
||||
|
||||
public isDisabled: Observable<boolean>;
|
||||
public undoDisabledObs: ko.Observable<boolean>;
|
||||
public redoDisabledObs: ko.Observable<boolean>;
|
||||
private _gristDoc: GristDoc;
|
||||
@@ -40,6 +40,8 @@ export class UndoStack extends dispose.Disposable {
|
||||
public create(log: MinimalActionGroup[], options: {gristDoc: GristDoc}) {
|
||||
this._gristDoc = options.gristDoc;
|
||||
|
||||
this.isDisabled = Observable.create(this, false);
|
||||
|
||||
// TODO: _stack and _linkMap grow without bound within a single session.
|
||||
// The top of the stack is stack.length - 1. The pointer points above the most
|
||||
// recently applied (not undone) action.
|
||||
@@ -99,15 +101,27 @@ export class UndoStack extends dispose.Disposable {
|
||||
}
|
||||
|
||||
// Send an undo action. This should be called when the user presses 'undo'.
|
||||
public sendUndoAction(): Promise<void> {
|
||||
public async sendUndoAction(): Promise<void> {
|
||||
if (this.isDisabled.get()) { return; }
|
||||
|
||||
return this._undoChain.add(() => this._sendAction(true));
|
||||
}
|
||||
|
||||
// Send a redo action. This should be called when the user presses 'redo'.
|
||||
public sendRedoAction(): Promise<void> {
|
||||
public async sendRedoAction(): Promise<void> {
|
||||
if (this.isDisabled.get()) { return; }
|
||||
|
||||
return this._undoChain.add(() => this._sendAction(false));
|
||||
}
|
||||
|
||||
public enable(): void {
|
||||
this.isDisabled.set(false);
|
||||
}
|
||||
|
||||
public disable(): void {
|
||||
this.isDisabled.set(true);
|
||||
}
|
||||
|
||||
private async _sendAction(isUndo: boolean): Promise<void> {
|
||||
// Pick the action group to undo or redo.
|
||||
const ag = this._stack[isUndo ? this._pointer - 1 : this._pointer];
|
||||
|
||||
Reference in New Issue
Block a user