From 63ef0c09587e8649425def7d8b82e931d6d00a13 Mon Sep 17 00:00:00 2001 From: "Jonathan (JB) Belcher" Date: Mon, 17 Aug 2020 13:18:31 -0400 Subject: [PATCH 1/7] Fix SelectAll, Undo, Redo --- desktop/app.js | 4 +-- desktop/context-menu/index.js | 45 +++++++++++++++++++++++++ desktop/menus/edit-menu.js | 6 ++-- desktop/spellchecker/index.js | 63 ----------------------------------- lib/note-content-editor.tsx | 15 +++++++++ 5 files changed, 65 insertions(+), 68 deletions(-) create mode 100644 desktop/context-menu/index.js delete mode 100644 desktop/spellchecker/index.js diff --git a/desktop/app.js b/desktop/app.js index 1468a15ba..c1335deb2 100644 --- a/desktop/app.js +++ b/desktop/app.js @@ -18,7 +18,7 @@ const importNotes = require('./evernote-import'); const platform = require('./detect/platform'); const updater = require('./updater'); const { isDev } = require('./env'); -const spellcheck = require('./spellchecker'); +const contextMenu = require('./context-menu'); require('module').globalPaths.push(path.resolve(path.join(__dirname))); @@ -76,7 +76,7 @@ module.exports = function main() { mainWindow.loadUrl(url); } - spellcheck(mainWindow); + contextMenu(mainWindow); if ( 'test' !== process.env.NODE_ENV && diff --git a/desktop/context-menu/index.js b/desktop/context-menu/index.js new file mode 100644 index 000000000..33a7fdc64 --- /dev/null +++ b/desktop/context-menu/index.js @@ -0,0 +1,45 @@ +'use strict'; + +/** + * External dependencies + */ +const { Menu } = require('electron'); + +const { appCommandSender } = require('../menus/utils'); + +module.exports = function (mainWindow) { + mainWindow.webContents.on('context-menu', (event, params) => { + const { editFlags } = params; + const template = [ + { + id: 'selectAll', + label: 'Select All', + 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/desktop/menus/edit-menu.js b/desktop/menus/edit-menu.js index fd4a14867..bd745e542 100644 --- a/desktop/menus/edit-menu.js +++ b/desktop/menus/edit-menu.js @@ -9,11 +9,11 @@ const buildEditMenu = (settings, isAuthenticated) => { submenu: [ { label: '&Undo', - role: 'undo', + click: appCommandSender({ action: 'undo' }), }, { label: '&Redo', - role: 'redo', + click: appCommandSender({ action: 'redo' }), }, { type: 'separator', @@ -32,7 +32,7 @@ const buildEditMenu = (settings, isAuthenticated) => { }, { label: '&Select All', - role: 'selectall', + click: appCommandSender({ action: 'selectAll' }), }, { type: 'separator' }, { diff --git a/desktop/spellchecker/index.js b/desktop/spellchecker/index.js deleted file mode 100644 index 8a6829ec6..000000000 --- a/desktop/spellchecker/index.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -/** - * External dependencies - */ -const { Menu, MenuItem } = require('electron'); - -module.exports = function (mainWindow) { - mainWindow.webContents.on('context-menu', (event, params) => { - const menu = new Menu(); - - const copy = new MenuItem({ label: 'Copy', role: 'copy' }); - - 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 - ), - }) - ); - } - - // 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({ - 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(); - }); -}; diff --git a/lib/note-content-editor.tsx b/lib/note-content-editor.tsx index 75b0dda50..6ae98025f 100644 --- a/lib/note-content-editor.tsx +++ b/lib/note-content-editor.tsx @@ -100,6 +100,7 @@ class NoteContentEditor extends Component { if (this.bootTimer) { clearTimeout(this.bootTimer); } + window?.electron.removeListener('editorCommand'); window.removeEventListener('keydown', this.handleKeys, true); } @@ -189,6 +190,20 @@ class NoteContentEditor extends Component { this.editor = editor; this.monaco = monaco; + window?.electron.receive('editorCommand', (command) => { + switch (command.action) { + case 'redo': + editor.trigger('', 'redo'); + return; + case 'selectAll': + editor.setSelection(editor.getModel().getFullModelRange()); + return; + case 'undo': + editor.trigger('', 'undo'); + return; + } + }); + const titleDecoration = (line: number) => ({ range: new monaco.Range(line, 1, line, 1), options: { From c4b5e76897dcf68afdda090317d9cd602b3ff9c0 Mon Sep 17 00:00:00 2001 From: "Jonathan (JB) Belcher" Date: Mon, 17 Aug 2020 13:20:48 -0400 Subject: [PATCH 2/7] Fix electron checks --- lib/note-content-editor.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/note-content-editor.tsx b/lib/note-content-editor.tsx index 6ae98025f..4d62462cc 100644 --- a/lib/note-content-editor.tsx +++ b/lib/note-content-editor.tsx @@ -100,7 +100,7 @@ class NoteContentEditor extends Component { if (this.bootTimer) { clearTimeout(this.bootTimer); } - window?.electron.removeListener('editorCommand'); + window.electron?.removeListener('editorCommand'); window.removeEventListener('keydown', this.handleKeys, true); } @@ -190,7 +190,7 @@ class NoteContentEditor extends Component { this.editor = editor; this.monaco = monaco; - window?.electron.receive('editorCommand', (command) => { + window.electron?.receive('editorCommand', (command) => { switch (command.action) { case 'redo': editor.trigger('', 'redo'); From 6d81a9ea5c15fef00d9829254f1298bb8543c803 Mon Sep 17 00:00:00 2001 From: "Jonathan (JB) Belcher" Date: Mon, 17 Aug 2020 13:38:43 -0400 Subject: [PATCH 3/7] Wire up editor command --- desktop/context-menu/index.js | 2 +- desktop/menus/edit-menu.js | 12 ++++++------ desktop/menus/file-menu.js | 8 ++++---- desktop/menus/format-menu.js | 2 +- desktop/menus/help-menu.js | 5 ++++- desktop/menus/menu-items.js | 8 ++++---- desktop/menus/utils.js | 6 +++--- desktop/menus/view-menu.js | 16 ++++++++++------ desktop/preload.js | 1 + 9 files changed, 34 insertions(+), 26 deletions(-) diff --git a/desktop/context-menu/index.js b/desktop/context-menu/index.js index 33a7fdc64..4f5bb1485 100644 --- a/desktop/context-menu/index.js +++ b/desktop/context-menu/index.js @@ -14,7 +14,7 @@ module.exports = function (mainWindow) { { id: 'selectAll', label: 'Select All', - click: appCommandSender({ action: 'selectAll' }), + click: appCommandSender('editorCommand', { action: 'selectAll' }), enabled: editFlags.canSelectAll, }, { diff --git a/desktop/menus/edit-menu.js b/desktop/menus/edit-menu.js index bd745e542..d5699e3f3 100644 --- a/desktop/menus/edit-menu.js +++ b/desktop/menus/edit-menu.js @@ -9,11 +9,11 @@ const buildEditMenu = (settings, isAuthenticated) => { submenu: [ { label: '&Undo', - click: appCommandSender({ action: 'undo' }), + click: appCommandSender('editorCommand', { action: 'undo' }), }, { label: '&Redo', - click: appCommandSender({ action: 'redo' }), + click: appCommandSender('editorCommand', { action: 'redo' }), }, { type: 'separator', @@ -32,19 +32,19 @@ const buildEditMenu = (settings, isAuthenticated) => { }, { label: '&Select All', - click: appCommandSender({ action: 'selectAll' }), + click: appCommandSender('editorCommand', { action: 'selectAll' }), }, { type: 'separator' }, { label: '&Trash Note', visible: isAuthenticated, - click: appCommandSender({ action: 'trashNote' }), + click: appCommandSender('appCommnad', { action: 'trashNote' }), }, { type: 'separator' }, { label: 'Search &Notes…', visible: isAuthenticated, - click: appCommandSender({ action: 'focusSearchField' }), + click: appCommandSender('appCommnad', { action: 'focusSearchField' }), }, { type: 'separator' }, { @@ -52,7 +52,7 @@ const buildEditMenu = (settings, isAuthenticated) => { visible: isAuthenticated, type: 'checkbox', checked: settings.spellCheckEnabled, - click: appCommandSender({ action: 'toggleSpellCheck' }), + click: appCommandSender('appCommnad', { action: 'toggleSpellCheck' }), }, ], }; diff --git a/desktop/menus/file-menu.js b/desktop/menus/file-menu.js index d63a0751e..870b4658b 100644 --- a/desktop/menus/file-menu.js +++ b/desktop/menus/file-menu.js @@ -10,13 +10,13 @@ const buildFileMenu = (isAuthenticated) => { label: '&New Note', visible: isAuthenticated, accelerator: 'CommandOrControl+Shift+I', - click: appCommandSender({ action: 'newNote' }), + click: appCommandSender('appCommnad', { action: 'newNote' }), }, { type: 'separator' }, { label: '&Import Notes…', visible: isAuthenticated, - click: appCommandSender({ + click: appCommandSender('appCommnad', { action: 'showDialog', dialog: 'IMPORT', }), @@ -25,7 +25,7 @@ const buildFileMenu = (isAuthenticated) => { label: '&Export Notes…', visible: isAuthenticated, accelerator: 'CommandOrControl+Shift+E', - click: appCommandSender({ + click: appCommandSender('appCommnad', { action: 'exportNotes', }), }, @@ -34,7 +34,7 @@ const buildFileMenu = (isAuthenticated) => { label: '&Print…', visible: isAuthenticated, accelerator: 'CommandOrControl+P', - click: appCommandSender({ action: 'printNote' }), + click: appCommandSender('appCommnad', { action: 'printNote' }), }, ]; diff --git a/desktop/menus/format-menu.js b/desktop/menus/format-menu.js index 79becb6d9..2e82145c3 100644 --- a/desktop/menus/format-menu.js +++ b/desktop/menus/format-menu.js @@ -6,7 +6,7 @@ const buildFormatMenu = (isAuthenticated) => { { label: 'Insert &Checklist', accelerator: 'CommandOrControl+Shift+C', - click: appCommandSender({ action: 'insertChecklist' }), + click: appCommandSender('appCommnad', { action: 'insertChecklist' }), }, ]; diff --git a/desktop/menus/help-menu.js b/desktop/menus/help-menu.js index 1beed0bd9..b7b9ca6ef 100644 --- a/desktop/menus/help-menu.js +++ b/desktop/menus/help-menu.js @@ -19,7 +19,10 @@ const buildHelpMenu = (mainWindow, isAuthenticated) => { { label: '&Keyboard Shortcuts', visible: isAuthenticated, - click: appCommandSender({ action: 'showDialog', dialog: 'KEYBINDINGS' }), + click: appCommandSender('appCommnad', { + action: 'showDialog', + dialog: 'KEYBINDINGS', + }), }, { type: 'separator' }, { diff --git a/desktop/menus/menu-items.js b/desktop/menus/menu-items.js index 89449dcc5..9115e5d66 100644 --- a/desktop/menus/menu-items.js +++ b/desktop/menus/menu-items.js @@ -5,7 +5,7 @@ const updater = require('../updater'); const about = { label: '&About ' + app.name, - click: appCommandSender({ + click: appCommandSender('appCommnad', { action: 'showDialog', dialog: 'ABOUT', }), @@ -20,7 +20,7 @@ const emptyTrash = (isAuthenticated) => { return { label: '&Empty Trash', visible: isAuthenticated, - click: appCommandSender({ action: 'emptyTrash' }), + click: appCommandSender('appCommnad', { action: 'emptyTrash' }), }; }; @@ -29,7 +29,7 @@ const preferences = (isAuthenticated) => { label: 'P&references…', visible: isAuthenticated, accelerator: 'CommandOrControl+,', - click: appCommandSender({ + click: appCommandSender('appCommnad', { action: 'showDialog', dialog: 'SETTINGS', }), @@ -40,7 +40,7 @@ const signout = (isAuthenticated) => { return { label: '&Sign Out', visible: isAuthenticated, - click: appCommandSender({ + click: appCommandSender('appCommnad', { action: 'logout', }), }; diff --git a/desktop/menus/utils.js b/desktop/menus/utils.js index 27d73a99d..1e2109863 100644 --- a/desktop/menus/utils.js +++ b/desktop/menus/utils.js @@ -5,7 +5,7 @@ const buildRadioGroup = ({ action, propName, settings }) => { return { type: 'radio', checked: id === settings[propName], - click: appCommandSender({ + click: appCommandSender('appCommnad', { action, [propName]: id, }), @@ -14,10 +14,10 @@ const buildRadioGroup = ({ action, propName, settings }) => { }; }; -const appCommandSender = (arg) => { +const appCommandSender = (commandName = 'appCommand', arg) => { return (item, focusedWindow) => { if (focusedWindow) { - focusedWindow.webContents.send('appCommand', arg); + focusedWindow.webContents.send(commandName, arg); } }; }; diff --git a/desktop/menus/view-menu.js b/desktop/menus/view-menu.js index 26cfbcdd6..f6fcf3989 100644 --- a/desktop/menus/view-menu.js +++ b/desktop/menus/view-menu.js @@ -40,7 +40,9 @@ const buildViewMenu = (settings, isAuthenticated) => { label: '&Reversed', type: 'checkbox', checked: settings.sortReversed, - click: appCommandSender({ action: 'toggleSortOrder' }), + click: appCommandSender('appCommnad', { + action: 'toggleSortOrder', + }), }, ]), }, @@ -96,7 +98,9 @@ const buildViewMenu = (settings, isAuthenticated) => { label: '&Sort Alphabetically', type: 'checkbox', checked: settings.sortTagsAlpha, - click: appCommandSender({ action: 'toggleSortTagsAlpha' }), + click: appCommandSender('appCommnad', { + action: 'toggleSortTagsAlpha', + }), }, ], }, @@ -128,19 +132,19 @@ const buildViewMenu = (settings, isAuthenticated) => { label: 'Zoom &In', visible: isAuthenticated, accelerator: 'CommandOrControl+=', - click: appCommandSender({ action: 'increaseFontSize' }), + click: appCommandSender('appCommnad', { action: 'increaseFontSize' }), }, { label: 'Zoom &Out', visible: isAuthenticated, accelerator: 'CommandOrControl+-', - click: appCommandSender({ action: 'decreaseFontSize' }), + click: appCommandSender('appCommnad', { action: 'decreaseFontSize' }), }, { label: '&Actual Size', visible: isAuthenticated, accelerator: 'CommandOrControl+0', - click: appCommandSender({ action: 'resetFontSize' }), + click: appCommandSender('appCommnad', { action: 'resetFontSize' }), }, { type: 'separator', @@ -152,7 +156,7 @@ const buildViewMenu = (settings, isAuthenticated) => { accelerator: 'CommandOrControl+Shift+F', type: 'checkbox', checked: settings.focusModeEnabled, - click: appCommandSender({ action: 'toggleFocusMode' }), + click: appCommandSender('appCommnad', { action: 'toggleFocusMode' }), }, { type: 'separator', diff --git a/desktop/preload.js b/desktop/preload.js index 8a477a19d..4114f9529 100644 --- a/desktop/preload.js +++ b/desktop/preload.js @@ -3,6 +3,7 @@ const { contextBridge, ipcRenderer, remote } = require('electron'); const validChannels = [ 'appCommand', 'clearCookies', + 'editorCommand', 'importNotes', 'noteImportChannel', 'setAutoHideMenuBar', From fc99cc3482bce34bdf8830b9063759f3cddfa912 Mon Sep 17 00:00:00 2001 From: Jonathan Belcher Date: Tue, 18 Aug 2020 11:27:17 -0400 Subject: [PATCH 4/7] Create editCommandSender --- desktop/context-menu/index.js | 4 ++-- desktop/menus/edit-menu.js | 14 +++++++------- desktop/menus/file-menu.js | 8 ++++---- desktop/menus/format-menu.js | 2 +- desktop/menus/help-menu.js | 2 +- desktop/menus/menu-items.js | 8 ++++---- desktop/menus/utils.js | 13 +++++++++++-- desktop/menus/view-menu.js | 12 ++++++------ 8 files changed, 36 insertions(+), 27 deletions(-) diff --git a/desktop/context-menu/index.js b/desktop/context-menu/index.js index 4f5bb1485..350f26035 100644 --- a/desktop/context-menu/index.js +++ b/desktop/context-menu/index.js @@ -5,7 +5,7 @@ */ const { Menu } = require('electron'); -const { appCommandSender } = require('../menus/utils'); +const { editCommandSender } = require('../menus/utils'); module.exports = function (mainWindow) { mainWindow.webContents.on('context-menu', (event, params) => { @@ -14,7 +14,7 @@ module.exports = function (mainWindow) { { id: 'selectAll', label: 'Select All', - click: appCommandSender('editorCommand', { action: 'selectAll' }), + click: editCommandSender({ action: 'selectAll' }), enabled: editFlags.canSelectAll, }, { diff --git a/desktop/menus/edit-menu.js b/desktop/menus/edit-menu.js index d5699e3f3..227205b20 100644 --- a/desktop/menus/edit-menu.js +++ b/desktop/menus/edit-menu.js @@ -1,4 +1,4 @@ -const { appCommandSender } = require('./utils'); +const { appCommandSender, editCommandSender } = require('./utils'); const buildEditMenu = (settings, isAuthenticated) => { settings = settings || {}; @@ -9,11 +9,11 @@ const buildEditMenu = (settings, isAuthenticated) => { submenu: [ { label: '&Undo', - click: appCommandSender('editorCommand', { action: 'undo' }), + click: editCommandSender({ action: 'undo' }), }, { label: '&Redo', - click: appCommandSender('editorCommand', { action: 'redo' }), + click: editCommandSender({ action: 'redo' }), }, { type: 'separator', @@ -32,19 +32,19 @@ const buildEditMenu = (settings, isAuthenticated) => { }, { label: '&Select All', - click: appCommandSender('editorCommand', { action: 'selectAll' }), + click: editCommandSender({ action: 'selectAll' }), }, { type: 'separator' }, { label: '&Trash Note', visible: isAuthenticated, - click: appCommandSender('appCommnad', { action: 'trashNote' }), + click: appCommandSender({ action: 'trashNote' }), }, { type: 'separator' }, { label: 'Search &Notes…', visible: isAuthenticated, - click: appCommandSender('appCommnad', { action: 'focusSearchField' }), + click: appCommandSender({ action: 'focusSearchField' }), }, { type: 'separator' }, { @@ -52,7 +52,7 @@ const buildEditMenu = (settings, isAuthenticated) => { visible: isAuthenticated, type: 'checkbox', checked: settings.spellCheckEnabled, - click: appCommandSender('appCommnad', { action: 'toggleSpellCheck' }), + click: appCommandSender({ action: 'toggleSpellCheck' }), }, ], }; diff --git a/desktop/menus/file-menu.js b/desktop/menus/file-menu.js index 870b4658b..d63a0751e 100644 --- a/desktop/menus/file-menu.js +++ b/desktop/menus/file-menu.js @@ -10,13 +10,13 @@ const buildFileMenu = (isAuthenticated) => { label: '&New Note', visible: isAuthenticated, accelerator: 'CommandOrControl+Shift+I', - click: appCommandSender('appCommnad', { action: 'newNote' }), + click: appCommandSender({ action: 'newNote' }), }, { type: 'separator' }, { label: '&Import Notes…', visible: isAuthenticated, - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'showDialog', dialog: 'IMPORT', }), @@ -25,7 +25,7 @@ const buildFileMenu = (isAuthenticated) => { label: '&Export Notes…', visible: isAuthenticated, accelerator: 'CommandOrControl+Shift+E', - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'exportNotes', }), }, @@ -34,7 +34,7 @@ const buildFileMenu = (isAuthenticated) => { label: '&Print…', visible: isAuthenticated, accelerator: 'CommandOrControl+P', - click: appCommandSender('appCommnad', { action: 'printNote' }), + click: appCommandSender({ action: 'printNote' }), }, ]; diff --git a/desktop/menus/format-menu.js b/desktop/menus/format-menu.js index 2e82145c3..79becb6d9 100644 --- a/desktop/menus/format-menu.js +++ b/desktop/menus/format-menu.js @@ -6,7 +6,7 @@ const buildFormatMenu = (isAuthenticated) => { { label: 'Insert &Checklist', accelerator: 'CommandOrControl+Shift+C', - click: appCommandSender('appCommnad', { action: 'insertChecklist' }), + click: appCommandSender({ action: 'insertChecklist' }), }, ]; diff --git a/desktop/menus/help-menu.js b/desktop/menus/help-menu.js index b7b9ca6ef..bbb811eba 100644 --- a/desktop/menus/help-menu.js +++ b/desktop/menus/help-menu.js @@ -19,7 +19,7 @@ const buildHelpMenu = (mainWindow, isAuthenticated) => { { label: '&Keyboard Shortcuts', visible: isAuthenticated, - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'showDialog', dialog: 'KEYBINDINGS', }), diff --git a/desktop/menus/menu-items.js b/desktop/menus/menu-items.js index 9115e5d66..89449dcc5 100644 --- a/desktop/menus/menu-items.js +++ b/desktop/menus/menu-items.js @@ -5,7 +5,7 @@ const updater = require('../updater'); const about = { label: '&About ' + app.name, - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'showDialog', dialog: 'ABOUT', }), @@ -20,7 +20,7 @@ const emptyTrash = (isAuthenticated) => { return { label: '&Empty Trash', visible: isAuthenticated, - click: appCommandSender('appCommnad', { action: 'emptyTrash' }), + click: appCommandSender({ action: 'emptyTrash' }), }; }; @@ -29,7 +29,7 @@ const preferences = (isAuthenticated) => { label: 'P&references…', visible: isAuthenticated, accelerator: 'CommandOrControl+,', - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'showDialog', dialog: 'SETTINGS', }), @@ -40,7 +40,7 @@ const signout = (isAuthenticated) => { return { label: '&Sign Out', visible: isAuthenticated, - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'logout', }), }; diff --git a/desktop/menus/utils.js b/desktop/menus/utils.js index 1e2109863..4d2e064b2 100644 --- a/desktop/menus/utils.js +++ b/desktop/menus/utils.js @@ -5,7 +5,7 @@ const buildRadioGroup = ({ action, propName, settings }) => { return { type: 'radio', checked: id === settings[propName], - click: appCommandSender('appCommnad', { + click: appCommandSender({ action, [propName]: id, }), @@ -14,7 +14,15 @@ const buildRadioGroup = ({ action, propName, settings }) => { }; }; -const appCommandSender = (commandName = 'appCommand', arg) => { +const appCommandSender = (arg) => { + commandSender('appCommand', arg); +}; + +const editCommandSender = (arg) => { + commandSender('editCommand', arg); +}; + +const commandSender = (commandName, arg) => { return (item, focusedWindow) => { if (focusedWindow) { focusedWindow.webContents.send(commandName, arg); @@ -25,4 +33,5 @@ const appCommandSender = (commandName = 'appCommand', arg) => { module.exports = { buildRadioGroup, appCommandSender, + editCommandSender, }; diff --git a/desktop/menus/view-menu.js b/desktop/menus/view-menu.js index f6fcf3989..2019013ea 100644 --- a/desktop/menus/view-menu.js +++ b/desktop/menus/view-menu.js @@ -40,7 +40,7 @@ const buildViewMenu = (settings, isAuthenticated) => { label: '&Reversed', type: 'checkbox', checked: settings.sortReversed, - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'toggleSortOrder', }), }, @@ -98,7 +98,7 @@ const buildViewMenu = (settings, isAuthenticated) => { label: '&Sort Alphabetically', type: 'checkbox', checked: settings.sortTagsAlpha, - click: appCommandSender('appCommnad', { + click: appCommandSender({ action: 'toggleSortTagsAlpha', }), }, @@ -132,19 +132,19 @@ const buildViewMenu = (settings, isAuthenticated) => { label: 'Zoom &In', visible: isAuthenticated, accelerator: 'CommandOrControl+=', - click: appCommandSender('appCommnad', { action: 'increaseFontSize' }), + click: appCommandSender({ action: 'increaseFontSize' }), }, { label: 'Zoom &Out', visible: isAuthenticated, accelerator: 'CommandOrControl+-', - click: appCommandSender('appCommnad', { action: 'decreaseFontSize' }), + click: appCommandSender({ action: 'decreaseFontSize' }), }, { label: '&Actual Size', visible: isAuthenticated, accelerator: 'CommandOrControl+0', - click: appCommandSender('appCommnad', { action: 'resetFontSize' }), + click: appCommandSender({ action: 'resetFontSize' }), }, { type: 'separator', @@ -156,7 +156,7 @@ const buildViewMenu = (settings, isAuthenticated) => { accelerator: 'CommandOrControl+Shift+F', type: 'checkbox', checked: settings.focusModeEnabled, - click: appCommandSender('appCommnad', { action: 'toggleFocusMode' }), + click: appCommandSender({ action: 'toggleFocusMode' }), }, { type: 'separator', From e3891608496d551b0e288ca392e40c8c2debe4e4 Mon Sep 17 00:00:00 2001 From: Jonathan Belcher Date: Tue, 18 Aug 2020 11:36:42 -0400 Subject: [PATCH 5/7] Update function names --- desktop/context-menu/index.js | 10 ++++------ desktop/menus/edit-menu.js | 8 ++++---- desktop/menus/utils.js | 6 +++--- lib/note-content-editor.tsx | 1 + 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/desktop/context-menu/index.js b/desktop/context-menu/index.js index 350f26035..b0bee4c4e 100644 --- a/desktop/context-menu/index.js +++ b/desktop/context-menu/index.js @@ -5,16 +5,16 @@ */ const { Menu } = require('electron'); -const { editCommandSender } = require('../menus/utils'); +const { editorCommandSender } = require('../menus/utils'); module.exports = function (mainWindow) { mainWindow.webContents.on('context-menu', (event, params) => { const { editFlags } = params; - const template = [ + Menu.buildFromTemplate([ { id: 'selectAll', label: 'Select All', - click: editCommandSender({ action: 'selectAll' }), + click: editorCommandSender({ action: 'selectAll' }), enabled: editFlags.canSelectAll, }, { @@ -38,8 +38,6 @@ module.exports = function (mainWindow) { { type: 'separator', }, - ]; - const menu = Menu.buildFromTemplate(template); - menu.popup({}); + ]).popup({}); }); }; diff --git a/desktop/menus/edit-menu.js b/desktop/menus/edit-menu.js index 227205b20..41e7fb1e6 100644 --- a/desktop/menus/edit-menu.js +++ b/desktop/menus/edit-menu.js @@ -1,4 +1,4 @@ -const { appCommandSender, editCommandSender } = require('./utils'); +const { appCommandSender, editorCommandSender } = require('./utils'); const buildEditMenu = (settings, isAuthenticated) => { settings = settings || {}; @@ -9,11 +9,11 @@ const buildEditMenu = (settings, isAuthenticated) => { submenu: [ { label: '&Undo', - click: editCommandSender({ action: 'undo' }), + click: editorCommandSender({ action: 'undo' }), }, { label: '&Redo', - click: editCommandSender({ action: 'redo' }), + click: editorCommandSender({ action: 'redo' }), }, { type: 'separator', @@ -32,7 +32,7 @@ const buildEditMenu = (settings, isAuthenticated) => { }, { label: '&Select All', - click: editCommandSender({ action: 'selectAll' }), + click: editorCommandSender({ action: 'selectAll' }), }, { type: 'separator' }, { diff --git a/desktop/menus/utils.js b/desktop/menus/utils.js index 4d2e064b2..78cd4bc09 100644 --- a/desktop/menus/utils.js +++ b/desktop/menus/utils.js @@ -18,8 +18,8 @@ const appCommandSender = (arg) => { commandSender('appCommand', arg); }; -const editCommandSender = (arg) => { - commandSender('editCommand', arg); +const editorCommandSender = (arg) => { + commandSender('editorCommand', arg); }; const commandSender = (commandName, arg) => { @@ -33,5 +33,5 @@ const commandSender = (commandName, arg) => { module.exports = { buildRadioGroup, appCommandSender, - editCommandSender, + editorCommandSender, }; diff --git a/lib/note-content-editor.tsx b/lib/note-content-editor.tsx index 4d62462cc..c61721bc6 100644 --- a/lib/note-content-editor.tsx +++ b/lib/note-content-editor.tsx @@ -191,6 +191,7 @@ class NoteContentEditor extends Component { this.monaco = monaco; window.electron?.receive('editorCommand', (command) => { + debugger; switch (command.action) { case 'redo': editor.trigger('', 'redo'); From 5da2edc489132811f72a3bf8298fc1527568e77d Mon Sep 17 00:00:00 2001 From: Jonathan Belcher Date: Tue, 18 Aug 2020 11:37:54 -0400 Subject: [PATCH 6/7] Fix command sender --- desktop/menus/utils.js | 4 ++-- lib/note-content-editor.tsx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/desktop/menus/utils.js b/desktop/menus/utils.js index 78cd4bc09..0e3116058 100644 --- a/desktop/menus/utils.js +++ b/desktop/menus/utils.js @@ -15,11 +15,11 @@ const buildRadioGroup = ({ action, propName, settings }) => { }; const appCommandSender = (arg) => { - commandSender('appCommand', arg); + return commandSender('appCommand', arg); }; const editorCommandSender = (arg) => { - commandSender('editorCommand', arg); + return commandSender('editorCommand', arg); }; const commandSender = (commandName, arg) => { diff --git a/lib/note-content-editor.tsx b/lib/note-content-editor.tsx index c61721bc6..4d62462cc 100644 --- a/lib/note-content-editor.tsx +++ b/lib/note-content-editor.tsx @@ -191,7 +191,6 @@ class NoteContentEditor extends Component { this.monaco = monaco; window.electron?.receive('editorCommand', (command) => { - debugger; switch (command.action) { case 'redo': editor.trigger('', 'redo'); From c11489be20db324200579f6a0dec22c58f61f27b Mon Sep 17 00:00:00 2001 From: Jonathan Belcher Date: Tue, 18 Aug 2020 11:40:55 -0400 Subject: [PATCH 7/7] Add editorCommand to types --- lib/global.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/global.d.ts b/lib/global.d.ts index 1785f302c..8e03924cd 100644 --- a/lib/global.d.ts +++ b/lib/global.d.ts @@ -11,6 +11,7 @@ declare global { confirmLogout(changes: string): 'logout' | 'reconsider' | 'export'; isMac: boolean; receive(command: 'appCommand', callback: (event: any) => any); + receive(command: 'editorCommand', callback: (event: any) => any); receive(command: 'noteImportChannel', callback: (event: any) => any); receive(command: 'wpLogin', callback: (event: any) => any); removeListener(command: 'noteImportChannel');