From 021ac3a093b5adc1b6ceaa12c45f2031620a6d98 Mon Sep 17 00:00:00 2001 From: "Klare, Heiko" Date: Mon, 6 Jul 2026 08:49:49 +0200 Subject: [PATCH] Find/Replace overlay: fix whole-word button enablement lagging by one keystroke The modify listener in createSearchBar() called wholeWordSearchButton.setEnabled(findReplaceLogic.isAvailable(WHOLE_WORD)) before updateIncrementalSearch(). Because updateIncrementalSearch() is what pushes the new search text into FindReplaceLogic.setFindString(), the isAvailable check always operated on the previous find string, causing the enabled state of the whole-word button to lag one keystroke behind. Move the setEnabled call to after updateIncrementalSearch() so that isAvailable(WHOLE_WORD) evaluates the current, already-updated find string. Add a regression test that sets a multi-word search term and immediately verifies the button is disabled, then sets a single-word term and verifies it is re-enabled, all without an intervening keystroke. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../findandreplace/overlay/FindReplaceOverlay.java | 2 +- .../overlay/FindReplaceOverlayTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java index ac389fd96a6..f5638e46464 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java @@ -701,8 +701,8 @@ private void createSearchBar() { searchBar.forceFocus(); searchBar.selectAll(); searchBar.addModifyListener(e -> { - wholeWordSearchButton.setEnabled(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD)); updateIncrementalSearch(); + wholeWordSearchButton.setEnabled(findReplaceLogic.isAvailable(SearchOptions.WHOLE_WORD)); decorate(); }); searchBar.addFocusListener(new FocusListener() { diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java index e74eb92d3b4..ddc82604ccc 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java @@ -201,6 +201,18 @@ public void testSearchTermStoredInHistoryAfterSearchForward() { assertEquals("foo", dialog.getFindText()); } + @Test + public void testWholeWordButtonEnabledStateImmediatelyReflectsCurrentSearchTerm() { + initializeTextViewerWithFindReplaceUI("foo bar foo"); + OverlayAccess dialog= getDialog(); + + dialog.setFindText("foo "); + dialog.assertDisabled(SearchOptions.WHOLE_WORD); + + dialog.setFindText("foo"); + dialog.assertEnabled(SearchOptions.WHOLE_WORD); + } + @Test public void testSearchTermStoredInHistoryAfterSearchBackward() { // Backward search must persist the term to history just like forward search.