From c409160ad7c3d25a2cb1cc024d1c4996cca0b4cb Mon Sep 17 00:00:00 2001 From: cagnusmarlsen <91818868+cagnusmarlsen@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:22:55 +0530 Subject: [PATCH] Desktop: Resolves #9980: Support Ctrl+Enter keyboard shortcut (Cmd+Enter on MacOS) (#10003) --- .../gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts | 2 ++ packages/editor/CodeMirror/createEditor.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts index 689067f79..ae0cfc4b0 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts @@ -145,6 +145,7 @@ export default function useKeymap(CodeMirror: any) { 'Alt-Right': 'goLineEnd', 'Ctrl-Backspace': 'delGroupBefore', 'Ctrl-Delete': 'delGroupAfter', + 'Ctrl-Enter': 'insertLineAfter', 'fallthrough': 'basic', }; @@ -167,6 +168,7 @@ export default function useKeymap(CodeMirror: any) { 'Alt-Backspace': 'delGroupBefore', 'Alt-Delete': 'delGroupAfter', 'Cmd-Backspace': 'delWrappedLineLeft', + 'Cmd-Enter': 'insertLineAfter', 'fallthrough': 'basic', }; diff --git a/packages/editor/CodeMirror/createEditor.ts b/packages/editor/CodeMirror/createEditor.ts index 89745e6e0..2d8076d9b 100644 --- a/packages/editor/CodeMirror/createEditor.ts +++ b/packages/editor/CodeMirror/createEditor.ts @@ -29,6 +29,7 @@ import { selectionFormattingEqual } from '../SelectionFormatting'; import configFromSettings from './configFromSettings'; import getScrollFraction from './getScrollFraction'; import CodeMirrorControl from './CodeMirrorControl'; +import insertLineAfter from './editorCommands/insertLineAfter'; const createEditor = ( parentElement: HTMLElement, props: EditorProps, @@ -261,6 +262,10 @@ const createEditor = ( }), keyCommand('Tab', insertOrIncreaseIndent, true), keyCommand('Shift-Tab', decreaseIndent, true), + keyCommand('Mod-Enter', (_: EditorView) => { + insertLineAfter(_); + return true; + }, true), ...standardKeymap, ...historyKeymap, ...searchKeymap, ]),