From 586e34efab4bd07256af339ef0c3e7d76c2f652e Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 4 Sep 2025 12:42:44 +0100 Subject: [PATCH] Avoid selecting next match when opening search form with no selected text (#28261) If a setSearchQuery effect is dispatched but the search query hasn't changed, avoid selecting the next match in the editor. GitOrigin-RevId: 8b0dda2b6c9442796a030214a37da7e93f4901f4 --- .../frontend/js/features/source-editor/extensions/search.ts | 5 +++++ 1 file changed, 5 insertions(+) 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 17fc4b027d..378cad2e26 100644 --- a/services/web/frontend/js/features/source-editor/extensions/search.ts +++ b/services/web/frontend/js/features/source-editor/extensions/search.ts @@ -250,6 +250,11 @@ export const search = (initialSearchQuery: SearchQuery | null) => { const query = effect.value if (!query) return + const currentQuery = getSearchQuery(tr.startState) + if (currentQuery === query) { + return // avoiding selecting the next match when opening the search form with no selected text + } + // The rest of this messes up searching in Vim, which is handled by // the Vim extension, so bail out here in Vim mode. Happily, the // Vim extension sticks an extra property on the query value that