From 94ef568328ed89f8aa8ec433b0d7da034ce74fd0 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 28 Apr 2023 09:41:24 +0100 Subject: [PATCH] [cm6] Avoid selecting a search match when re-opening the search panel (#12797) GitOrigin-RevId: 32bb03b71ce56cc0dbe6f7c92cc6d85151ef1971 --- .../frontend/js/features/source-editor/extensions/search.ts | 5 +++++ .../components/codemirror-editor-shortcuts.spec.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/search.ts b/services/web/frontend/js/features/source-editor/extensions/search.ts index 3aa31a59ef..2e3eaeebd2 100644 --- a/services/web/frontend/js/features/source-editor/extensions/search.ts +++ b/services/web/frontend/js/features/source-editor/extensions/search.ts @@ -126,6 +126,11 @@ export const search = () => { // select a match while searching EditorView.updateListener.of(update => { + // if the search panel wasn't open, don't select a match + if (!searchPanelOpen(update.startState)) { + return + } + for (const tr of update.transactions) { // avoid changing the selection and viewport when switching between files if (tr.annotation(restoreSearchQueryAnnotation)) { diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx index 486a21ce04..e57a0e8572 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx @@ -221,7 +221,7 @@ contentLine3 // Search should now be open at first match cy.findByRole('search').should('have.length', 1) - cy.contains(`1 of 3`) + cy.contains(`0 of 3`) // Repeated C-r should go to previous match cy.get('@search-input').type('{ctrl}r')