diff --git a/desktop/menus/edit-menu.js b/desktop/menus/edit-menu.js index ab58170ae..319837cb6 100644 --- a/desktop/menus/edit-menu.js +++ b/desktop/menus/edit-menu.js @@ -66,7 +66,7 @@ const buildEditMenu = (settings, isAuthenticated, editMode) => { { label: '&Find in Note', visible: isAuthenticated, - click: editorCommandSender({ action: 'find' }), + click: appCommandSender({ action: 'focusSearchField' }), accelerator: 'CommandOrControl+F', }, { diff --git a/lib/app.tsx b/lib/app.tsx index 510e7af62..38ffb7de1 100644 --- a/lib/app.tsx +++ b/lib/app.tsx @@ -92,6 +92,27 @@ class AppComponent extends Component { return false; } + if (('Escape' === key || 'Esc' === key) && this.props.isSearchActive) { + this.props.clearSearch(); + } + + if (!window.electron) { + this.handleBrowserShortcut(event); + } + + return true; + }; + + // handle all keyboard shortcuts that are duplicated in the Electron menus + // this listener is only called in browsers, as otherwise the + // menu will trigger them via the provided Accelerator, so we don't need a listener + handleBrowserShortcut = (event: KeyboardEvent) => { + const { ctrlKey, metaKey, shiftKey } = event; + const key = event.key.toLowerCase(); + + // Is either cmd or ctrl pressed? (But not both) + const cmdOrCtrl = (ctrlKey || metaKey) && ctrlKey !== metaKey; + if ( (cmdOrCtrl && shiftKey && 's' === key) || (cmdOrCtrl && !shiftKey && 'f' === key) @@ -103,10 +124,6 @@ class AppComponent extends Component { return false; } - if (('Escape' === key || 'Esc' === key) && this.props.isSearchActive) { - this.props.clearSearch(); - } - if (cmdOrCtrl && shiftKey && 'f' === key) { this.props.toggleFocusMode(); @@ -128,8 +145,6 @@ class AppComponent extends Component { event.stopPropagation(); event.preventDefault(); } - - return true; }; toggleShortcuts = (doEnable: boolean) => { diff --git a/lib/note-content-editor.tsx b/lib/note-content-editor.tsx index 0952bbcb5..75178d53f 100644 --- a/lib/note-content-editor.tsx +++ b/lib/note-content-editor.tsx @@ -178,7 +178,8 @@ class NoteContentEditor extends Component { return false; } - if (cmdOrCtrl && !shiftKey && key === 'g') { + // Electron can trigger this from the menu + if (!window.electron && cmdOrCtrl && !shiftKey && key === 'g') { this.setNextSearchSelection(); event.stopPropagation(); event.preventDefault();