Skip to content

Commit 6dcd646

Browse files
Maximilian WittmerHeikoKlare
Maximilian Wittmer
authored andcommitted
Fix correctly setting Find-Scopes when opening Find/Replace-Dialog eclipse-platform#1819
This PR correctly disables SearchOptions.GLOBAL in the FindReplaceLogic object of the Dialog if a multiline-selection was selected while opening the Find/Replace-Dialog. This PR also provides a unit-test for this behavior. Fixes eclipse-platform#1819
1 parent 3c12155 commit 6dcd646

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java

+1
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ private void initFindStringFromSelection() {
946946
} else {
947947
fGlobalRadioButton.setSelection(false);
948948
fSelectedRangeRadioButton.setSelection(true);
949+
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
949950
}
950951
}
951952

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceDialogTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.workbench.texteditor.tests;
1515

16+
import static org.hamcrest.MatcherAssert.assertThat;
17+
import static org.hamcrest.Matchers.is;
1618
import static org.junit.Assert.assertEquals;
1719
import static org.junit.Assert.assertFalse;
1820
import static org.junit.Assert.assertTrue;
@@ -98,6 +100,8 @@ private class DialogAccess {
98100

99101
private Runnable closeOperation;
100102

103+
public Button replaceAllButton;
104+
101105

102106
DialogAccess(Accessor findReplaceDialogAccessor, boolean checkInitialConfiguration) {
103107
findReplaceLogic= (FindReplaceLogic) findReplaceDialogAccessor.get("findReplaceLogic");
@@ -110,6 +114,7 @@ private class DialogAccess {
110114
incrementalCheckBox= (Button) findReplaceDialogAccessor.get("fIncrementalCheckBox");
111115
regExCheckBox= (Button) findReplaceDialogAccessor.get("fIsRegExCheckBox");
112116
replaceFindButton= (Button) findReplaceDialogAccessor.get("fReplaceFindButton");
117+
replaceAllButton= (Button) findReplaceDialogAccessor.get("fReplaceAllButton");
113118
shellRetriever= () -> ((Shell) findReplaceDialogAccessor.get("fActiveShell"));
114119
closeOperation= () -> findReplaceDialogAccessor.invoke("close", null);
115120
if (checkInitialConfiguration) {
@@ -426,6 +431,19 @@ public void testActivateWholeWordsAndSearchForTwoWords() {
426431
assertFalse(dialog.wholeWordCheckBox.getEnabled());
427432
}
428433

434+
@Test
435+
public void testActivateDialogWithSelectionActive() {
436+
openTextViewer("text" + System.lineSeparator() + "text" + System.lineSeparator() + "text");
437+
fTextViewer.setSelectedRange(4 + System.lineSeparator().length(), 8 + System.lineSeparator().length());
438+
openFindReplaceDialogForTextViewer(false);
439+
440+
assertFalse(dialog.globalRadioButton.getSelection());
441+
dialog.findCombo.setText("text");
442+
select(dialog.replaceAllButton);
443+
444+
assertThat(fTextViewer.getDocument().get(), is("text" + System.lineSeparator() + System.lineSeparator()));
445+
}
446+
429447
@Test
430448
public void testIncrementalSearchOnlyEnabledWhenAllowed() {
431449
openTextViewer("text text text");

0 commit comments

Comments
 (0)