From 22dc7def0958b41c618015975b078324eb706a18 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 17 Jul 2026 15:15:18 +0200 Subject: [PATCH] Find/replace overlay: add test for proper shortcut hints Add regression coverage for the recent fix on the search/replace bars' buttons only showing their shortcut-hint tooltip suffix while the corresponding input field actually has focus, rather than always showing hints for actions that are not currently reachable via that shortcut. Co-authored-by: Claude Sonnet 5 --- .../overlay/FindReplaceOverlayTest.java | 23 +++++++++++++++++++ .../findandreplace/overlay/OverlayAccess.java | 8 +++++++ 2 files changed, 31 insertions(+) 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 ad117b7ad4d..f7fce499b64 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 @@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; @@ -30,6 +31,7 @@ import org.eclipse.text.tests.Accessor; +import org.eclipse.jface.bindings.keys.KeyStroke; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.text.IFindReplaceTarget; @@ -57,6 +59,27 @@ public OverlayAccess openUIFromTextViewer(TextViewer viewer) { return uiAccess; } + @Test + public void testShortcutHintReflectsFocusedInputField() { + initializeTextViewerWithFindReplaceUI("line"); + OverlayAccess dialog= getDialog(); + + String searchForwardHint= KeyStroke.getInstance(SWT.CR).format(); + + // The search bar has focus right after opening: its own shortcut hint is shown. + assertTrue(dialog.getSearchForwardToolTipText().contains(searchForwardHint)); + + // Opening the replace bar moves focus there: the search-scoped hint disappears and the + // replace-scoped hint (which happens to reuse the same shortcut) appears instead. + dialog.openReplaceDialog(); + assertFalse(dialog.getSearchForwardToolTipText().contains(searchForwardHint)); + assertTrue(dialog.getReplaceToolTipText().contains(searchForwardHint)); + + // Closing the replace bar returns focus to the search bar: its hint is shown again. + dialog.closeReplaceDialog(); + assertTrue(dialog.getSearchForwardToolTipText().contains(searchForwardHint)); + } + @Test public void testDirectionalSearchButtons() { initializeTextViewerWithFindReplaceUI("line\nline\nline\nline"); diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java index 1b0c0d70150..74b8b1c6c25 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/OverlayAccess.java @@ -254,6 +254,14 @@ public void performReplace() { replaceButton.notifyListeners(SWT.Selection, null); } + public String getSearchForwardToolTipText() { + return searchForward.getToolTipText(); + } + + public String getReplaceToolTipText() { + return replaceButton != null ? replaceButton.getToolTipText() : null; + } + public boolean isReplaceDialogOpen() { return replace != null; }