diff --git a/src/editor/index.ts b/src/editor/index.ts index 3e24a64..c69cc2b 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -91,13 +91,14 @@ export const editor: JupyterFrontEndPlugin = { const isEnabled = () => { const widget = tracker.currentWidget; - if (!widget) { - return false; + if (widget?.isVisible && widget === app.shell.currentWidget) { + return true; } - return true; + return false; }; commands.addCommand(CommandIDs.redo, { + label: 'Redo', execute: () => { const widget = tracker.currentWidget; if (!widget) { @@ -105,10 +106,10 @@ export const editor: JupyterFrontEndPlugin = { } widget.redo(); }, - isEnabled, }); commands.addCommand(CommandIDs.undo, { + label: 'Undo', execute: () => { const widget = tracker.currentWidget; if (!widget) { @@ -116,16 +117,17 @@ export const editor: JupyterFrontEndPlugin = { } widget.undo(); }, - isEnabled, }); // Add undo/redo hooks to the edit menu. mainMenu.editMenu.undoers.undo.add({ id: CommandIDs.undo, + isEnabled, }); // Add undo/redo hooks to the edit menu. mainMenu.editMenu.undoers.redo.add({ id: CommandIDs.redo, + isEnabled, }); app.docRegistry.addWidgetFactory(factory);