diff --git a/desktop/menus/edit-menu.js b/desktop/menus/edit-menu.js index 9922180b2..ff6bf16ee 100644 --- a/desktop/menus/edit-menu.js +++ b/desktop/menus/edit-menu.js @@ -8,11 +8,11 @@ const buildEditMenu = (settings) => { submenu: [ { label: '&Undo', - role: 'undo', + click: appCommandSender({ action: 'undo' }), }, { label: '&Redo', - role: 'redo', + click: appCommandSender({ action: 'redo' }), }, { type: 'separator', @@ -31,7 +31,7 @@ const buildEditMenu = (settings) => { }, { label: '&Select All', - role: 'selectall', + click: appCommandSender({ action: 'selectAll' }), }, { type: 'separator' }, { diff --git a/desktop/spellchecker/index.js b/desktop/spellchecker/index.js index 8a6829ec6..6cad5017f 100644 --- a/desktop/spellchecker/index.js +++ b/desktop/spellchecker/index.js @@ -5,59 +5,70 @@ */ const { Menu, MenuItem } = require('electron'); +const { appCommandSender } = require('../menus/utils'); + module.exports = function (mainWindow) { mainWindow.webContents.on('context-menu', (event, params) => { - const menu = new Menu(); + const { editFlags } = params; - const copy = new MenuItem({ label: 'Copy', role: 'copy' }); + // // Add each spelling suggestion + // for (const suggestion of params.dictionarySuggestions) { + // menu.append( + // new MenuItem({ + // label: suggestion, + // click: () => mainWindow.webContents.replaceMisspelling(suggestion), + // }) + // ); + // } - if (!params.isEditable) { - // If text is not editable, only permit the `Copy` action - menu.append(copy); - } else { - // Add each spelling suggestion - for (const suggestion of params.dictionarySuggestions) { - menu.append( - new MenuItem({ - label: suggestion, - click: () => mainWindow.webContents.replaceMisspelling(suggestion), - }) - ); - } + // // Allow users to add the misspelled word to the dictionary + // if (params.misspelledWord) { + // menu.append(new MenuItem({ type: 'separator' })); + // menu.append( + // new MenuItem({ + // label: 'Add to Dictionary', + // click: () => + // mainWindow.webContents.session.addWordToSpellCheckerDictionary( + // params.misspelledWord + // ), + // }) + // ); + // } - // Allow users to add the misspelled word to the dictionary - if (params.misspelledWord) { - menu.append(new MenuItem({ type: 'separator' })); - menu.append( - new MenuItem({ - label: 'Add to Dictionary', - click: () => - mainWindow.webContents.session.addWordToSpellCheckerDictionary( - params.misspelledWord - ), - }) - ); - } + // if (params?.dictionarySuggestions?.length > 0) { + // menu.append(new MenuItem({ type: 'separator' })); + // } - // If text is editable, permit the Select All, Cut, Copy and Paste actions - const cut = new MenuItem({ label: 'Cut', role: 'cut' }); - const paste = new MenuItem({ label: 'Paste', role: 'paste' }); - const selectAll = new MenuItem({ + const template = [ + { + id: 'selectAll', label: 'Select All', - role: 'selectAll', - }); - - const menuItems = [selectAll, cut, copy, paste]; - - if (params?.dictionarySuggestions?.length > 0) { - menu.append(new MenuItem({ type: 'separator' })); - } - - for (const item of menuItems) { - menu.append(item); - } - } - - menu.popup(); + click: appCommandSender({ action: 'selectAll' }), + enabled: editFlags.canSelectAll, + }, + { + id: 'cut', + label: 'Cut', + role: 'cut', + enabled: editFlags.canCut, + }, + { + id: 'copy', + label: 'Copy', + role: 'copy', + enabled: editFlags.canCopy, + }, + { + id: 'paste', + label: 'Paste', + role: 'paste', + enabled: editFlags.canPaste, + }, + { + type: 'separator', + }, + ]; + const menu = Menu.buildFromTemplate(template); + menu.popup({}); }); }; diff --git a/lib/state/electron/middleware.ts b/lib/state/electron/middleware.ts index 72e4861c0..bca7d5eaa 100644 --- a/lib/state/electron/middleware.ts +++ b/lib/state/electron/middleware.ts @@ -45,10 +45,20 @@ export const middleware: S.Middleware = ({ dispatch, getState }) => { dispatch(actions.settings.decreaseFontSize()); return; + case 'redo': + window?.editor.trigger('', 'redo'); + return; + case 'resetFontSize': dispatch(actions.settings.resetFontSize()); return; + case 'selectAll': + window?.editor.setSelection( + window?.editor.getModel().getFullModelRange() + ); + return; + case 'setLineLength': dispatch(actions.settings.setLineLength(command.lineLength)); return; @@ -77,6 +87,10 @@ export const middleware: S.Middleware = ({ dispatch, getState }) => { dispatch(actions.settings.toggleSpellCheck()); return; + case 'undo': + window?.editor.trigger('', 'undo'); + return; + default: console.log(command); }