From 17098dc4f9726f7035d7c385a3da5b338d514fd7 Mon Sep 17 00:00:00 2001 From: Sindre Gulseth Date: Mon, 25 Mar 2024 00:42:36 +0100 Subject: [PATCH] fix(vision): fixes bug where codemirror would insert a new line on cmd-return --- .../@sanity/vision/src/codemirror/extensions.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/@sanity/vision/src/codemirror/extensions.ts b/packages/@sanity/vision/src/codemirror/extensions.ts index 7cb17b2876b..d8e246e6c45 100644 --- a/packages/@sanity/vision/src/codemirror/extensions.ts +++ b/packages/@sanity/vision/src/codemirror/extensions.ts @@ -8,7 +8,7 @@ import { syntaxHighlighting, } from '@codemirror/language' import {highlightSelectionMatches} from '@codemirror/search' -import {Extension} from '@codemirror/state' +import {type Extension} from '@codemirror/state' import { drawSelection, highlightActiveLine, @@ -31,5 +31,16 @@ export const codemirrorExtensions: Extension[] = [ history(), drawSelection(), syntaxHighlighting(defaultHighlightStyle, {fallback: true}), - keymap.of([defaultKeymap, historyKeymap].flat().filter(Boolean)), + keymap.of( + [ + // Override the default keymap for Mod-Enter to not insert a new line, we have a custom event handler for executing queries + {key: 'Mod-Enter', run: () => true}, + + // Add the default keymap and history keymap + defaultKeymap, + historyKeymap, + ] + .flat() + .filter(Boolean), + ), ]