From f9414d2e8a88a92e7754173b40c18ce15c79c0f8 Mon Sep 17 00:00:00 2001 From: ahrefabhi Date: Mon, 7 Jul 2025 15:56:12 +0530 Subject: [PATCH] feat: enhance keymap handling in QuerySearch to prevent default line breaks on Enter keys --- .../QueryV2/QuerySearch/QuerySearch.tsx | 51 +++++++++++++++---- frontend/src/utils/queryContextUtils.ts | 1 - 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx index e6229e1fe6b7..ce60fde01418 100644 --- a/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx +++ b/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx @@ -12,8 +12,8 @@ import { import { javascript } from '@codemirror/lang-javascript'; import { Color } from '@signozhq/design-tokens'; import { copilot } from '@uiw/codemirror-theme-copilot'; -import CodeMirror, { EditorView, keymap } from '@uiw/react-codemirror'; -import { Button, Card, Collapse, Popover, Space, Tag, Typography } from 'antd'; +import CodeMirror, { EditorView, keymap, Prec } from '@uiw/react-codemirror'; +import { Button, Card, Collapse, Popover, Tag } from 'antd'; import { getKeySuggestions } from 'api/querySuggestions/getKeySuggestions'; import { getValueSuggestions } from 'api/querySuggestions/getValueSuggestion'; import cx from 'classnames'; @@ -1046,13 +1046,42 @@ function QuerySearch({ javascript({ jsx: false, typescript: false }), EditorView.lineWrapping, stopEventsExtension, - keymap.of([ - ...completionKeymap, - { - key: 'Escape', - run: closeCompletion, - }, - ]), + Prec.highest( + keymap.of([ + ...completionKeymap, + { + key: 'Escape', + run: closeCompletion, + }, + { + key: 'Enter', + preventDefault: true, + // Prevent default behavior of Enter to add new line + // and instead run a custom action + run: (): boolean => { + return true; + }, + }, + { + key: 'Mod-Enter', + preventDefault: true, + // Prevent default behavior of Mod-Enter to add new line + // and instead run a custom action + // Mod-Enter is usually Ctrl-Enter or Cmd-Enter based on OS + run: (): boolean => { + return true; + }, + }, + { + key: 'Shift-Enter', + preventDefault: true, + // Prevent default behavior of Shift-Enter to add new line + run: (): boolean => { + return true; + }, + }, + ]), + ), ]} placeholder="Enter your query (e.g., status = 'error' AND service = 'frontend')" basicSetup={{ @@ -1154,7 +1183,7 @@ function QuerySearch({ )} - {queryContext && ( + {/* {queryContext && (
@@ -1196,7 +1225,7 @@ function QuerySearch({
- )} + )} */} ); } diff --git a/frontend/src/utils/queryContextUtils.ts b/frontend/src/utils/queryContextUtils.ts index c68c795c4bb1..0de259738128 100644 --- a/frontend/src/utils/queryContextUtils.ts +++ b/frontend/src/utils/queryContextUtils.ts @@ -13,7 +13,6 @@ import { isNonValueOperatorToken, isOperatorToken, isValueToken, - isWrappedUnderQuotes, } from './tokenUtils'; // Function to normalize multiple spaces to single spaces when not in quotes