From f83d95136dbbc1fc348a55b75fc37c31344c47b4 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 20 Jan 2026 16:11:40 +0200 Subject: [PATCH] fix(codemirror): ctrl+enter generates newline --- packages/codemirror/src/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.ts index c86d37b12..f77342455 100644 --- a/packages/codemirror/src/index.ts +++ b/packages/codemirror/src/index.ts @@ -1,5 +1,5 @@ import { defaultKeymap, history, historyKeymap } from "@codemirror/commands"; -import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewPlugin, ViewUpdate, type EditorViewConfig } from "@codemirror/view"; +import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewPlugin, ViewUpdate, type EditorViewConfig, KeyBinding } from "@codemirror/view"; import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter, codeFolding } from "@codemirror/language"; import { Compartment, EditorSelection, EditorState, type Extension } from "@codemirror/state"; import { highlightSelectionMatches } from "@codemirror/search"; @@ -12,6 +12,17 @@ import { createSearchHighlighter, SearchHighlighter, searchMatchHighlightTheme } export { default as ColorThemes, type ThemeDefinition, getThemeById } from "./color_themes.js"; +// Custom keymap to prevent Ctrl+Enter from inserting a newline +// This allows the parent application to handle the shortcut (e.g., for "Run Active Note") +const preventCtrlEnterKeymap: readonly KeyBinding[] = [ + { + key: "Ctrl-Enter", + mac: "Cmd-Enter", + run: () => true, // Return true to mark event as handled, preventing default newline insertion + preventDefault: true + } +]; + type ContentChangedListener = () => void; export interface EditorConfig { @@ -59,6 +70,7 @@ export default class CodeMirror extends EditorView { lineNumbers(), indentUnit.of(" ".repeat(4)), keymap.of([ + ...preventCtrlEnterKeymap, ...defaultKeymap, ...historyKeymap, ...smartIndentWithTab