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 525489111cc..bd441081f68 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 @@ -948,6 +948,7 @@ private void updateFromTargetSelection() { } searchBar.setText(selectionText); searchBar.setSelection(0, selectionText.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 9acb946d600..f89e8648d06 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 @@ -331,6 +331,18 @@ public void testActivateDialogSelectionActive_withRegExOptionActivated() { assertThat(fTextViewer.getDocument().get(), is("test ;")); } + @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; }