From 8a12c34fce422a4ff1f001782088fcb3d7681341 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 3 May 2023 09:26:36 +0100 Subject: [PATCH] [cm6] Emacs: close search form when `Enter` is pressed in "Find" input (#12841) GitOrigin-RevId: a4c974f45e0dbb13d96b9b424f056768449791fb --- .../components/codemirror-search-form.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx b/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx index 11662f7d9a..bd110ae9c3 100644 --- a/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx +++ b/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx @@ -23,7 +23,7 @@ import classnames from 'classnames' import useScopeValue from '../../../shared/hooks/use-scope-value' import { getStoredSelection, setStoredSelection } from '../extensions/search' import { debounce } from 'lodash' -import { EditorState } from '@codemirror/state' +import { EditorSelection, EditorState } from '@codemirror/state' const MATCH_COUNT_DEBOUNCE_WAIT = 100 // the amount of ms to wait before counting matches const MAX_MATCH_COUNT = 999 // the maximum number of matches to count @@ -169,7 +169,12 @@ const CodeMirrorSearchForm: FC = () => { switch (event.key) { case 'Enter': event.preventDefault() - if (event.shiftKey) { + if (emacsKeybindingsActive) { + closeSearchPanel(view) + view.dispatch({ + selection: EditorSelection.cursor(view.state.selection.main.to), + }) + } else if (event.shiftKey) { findPrevious(view) } else { findNext(view) @@ -178,7 +183,7 @@ const CodeMirrorSearchForm: FC = () => { } handleEmacsNavigation(event) }, - [view, handleEmacsNavigation] + [view, handleEmacsNavigation, emacsKeybindingsActive] ) const handleReplaceKeyDown = useCallback(