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 b7d737c403a..0378925b6d8 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 @@ -870,6 +870,7 @@ private void updateFromTargetSelection() { } else { searchBar.setText(initText); searchBar.setSelection(0, initText.length()); + findReplaceLogic.findAndSelect(findReplaceLogic.getTarget().getSelection().x, searchBar.getText()); } } diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java index 7732051f6d6..5347e096bd5 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java @@ -291,6 +291,18 @@ public void testActivateDialogWithSelectionActive() { assertThat(fTextViewer.getDocument().get(), is("text" + System.lineSeparator() + System.lineSeparator())); } + @Test + public void testReplaceIfSelectedOnStart() { + openTextViewer("abcdefg"); + fTextViewer.setSelection(new TextSelection(2, 2)); + initializeFindReplaceUIForTextViewer(); + + dialog.setReplaceText("aa"); + dialog.performReplace(); + + assertThat(fTextViewer.getDocument().get(), is("abaaefg")); + } + protected AccessType getDialog() { return dialog; }