(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:
George Gevoian
2023-07-18 22:27:53 -04:00
parent c0ed4a8a60
commit 0040716006
3 changed files with 43 additions and 8 deletions

View File

@@ -70,6 +70,14 @@ export function createTopBarDoc(owner: MultiHolder, appModel: AppModel, pageMode
return module.SearchModelImpl.create(use.owner, gristDoc);
});
const isUndoRedoAvailable = Computed.create(owner, use => {
const gristDoc = use(pageModel.gristDoc);
if (!gristDoc) { return false; }
const undoStack = gristDoc.getUndoStack();
return !use(undoStack.isDisabled);
});
return [
// TODO Before gristDoc is loaded, we could show doc-name without the page. For now, we delay
// showing of breadcrumbs until gristDoc is loaded.
@@ -98,14 +106,14 @@ export function createTopBarDoc(owner: MultiHolder, appModel: AppModel, pageMode
topBarUndoBtn('Undo',
dom.on('click', () => state.isUndoDisabled.get() || allCommands.undo.run()),
hoverTooltip('Undo', {key: 'topBarBtnTooltip'}),
cssHoverCircle.cls('-disabled', state.isUndoDisabled),
testId('undo')
cssHoverCircle.cls('-disabled', use => use(state.isUndoDisabled) || !use(isUndoRedoAvailable)),
testId('undo'),
),
topBarUndoBtn('Redo',
dom.on('click', () => state.isRedoDisabled.get() || allCommands.redo.run()),
hoverTooltip('Redo', {key: 'topBarBtnTooltip'}),
cssHoverCircle.cls('-disabled', state.isRedoDisabled),
testId('redo')
cssHoverCircle.cls('-disabled', use => use(state.isRedoDisabled) || !use(isUndoRedoAvailable)),
testId('redo'),
),
cssSpacer(),
]),