Просмотр исходного кода

[cm6] Avoid selecting a search match when re-opening the search panel (#12797)

GitOrigin-RevId: 32bb03b71ce56cc0dbe6f7c92cc6d85151ef1971
Alf Eaton 3 лет назад
Родитель
Сommit
1da94f029c

+ 5 - 0
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)) {

+ 1 - 1
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')