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 3600139805d..4f0303aac58 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 @@ -874,6 +874,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; }