Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(codemirror): ctrl+enter generates newline
Elian Doranf83d95136dbb
diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex c86d37b12d..f77342455d 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