From 971ba9f65b5e2a1b78f46a4612dc56f2a02bdff5 Mon Sep 17 00:00:00 2001 From: Sindre Gulseth Date: Tue, 26 Mar 2024 10:47:24 +0100 Subject: [PATCH] fix(vision): fixes bug where codemirror would insert a new line on cmd-return (#6123) --- .../@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), + ), ]