Skip to content

Commit 58bb65c

Browse files
committed
FindReplaceOverlay: use search-as-you-type in regex mode #1911
Currently, the FindReplaceLogic disables the incremental mode (i.e., search-as-you-type) in case the regex search option is activated. This makes the FindReplaceOverlay, which uses search-as-you-type in all other situations, behave non-intuitively when the regex option is activated. In order to achieve consistent, user-expectable behavior of the find and replace functionality and because of lacking arguments against using search-as-you-type in regex mode, this change makes the regex search mode independent from the incremental mode of the FindReplaceLogic. In consequence, the FindReplaceOverlay always uses search-as-you-type, no matter which search options are activated. In addition, explicit test code for that exceptional behavior is removed or adapted. Contributes to #2066 Contributes to #2646 Fixes #1911
1 parent 36c6b93 commit 58bb65c

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ private void resetStatus() {
132132
@Override
133133
public boolean isAvailable(SearchOptions searchOption) {
134134
switch (searchOption) {
135-
case INCREMENTAL:
136-
return !isAvailableAndActive(SearchOptions.REGEX);
137135
case REGEX:
138136
return isTargetSupportingRegEx;
139137
case WHOLE_WORD:
140138
return !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString);
139+
case INCREMENTAL:
141140
case CASE_SENSITIVE:
142141
case FORWARD:
143142
case GLOBAL:

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ public void widgetSelected(SelectionEvent e) {
589589
return;
590590
}
591591
findReplaceLogic.activate(SearchOptions.GLOBAL);
592+
updateFindString();
592593
}
593594

594595
@Override
@@ -608,6 +609,7 @@ public void widgetSelected(SelectionEvent e) {
608609
return;
609610
}
610611
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
612+
updateFindString();
611613
}
612614

613615
@Override
@@ -650,11 +652,7 @@ private Composite createInputPanel(Composite parent) {
650652
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
651653
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
652654
addDecorationMargin(fFindField);
653-
fFindModifyListener = new InputModifyListener(() -> {
654-
if (okToUse(fFindField)) {
655-
findReplaceLogic.setFindString(fFindField.getText());
656-
}
657-
});
655+
fFindModifyListener = new InputModifyListener(this::updateFindString);
658656
fFindField.addModifyListener(fFindModifyListener);
659657

660658
fReplaceLabel = new Label(panel, SWT.LEFT);
@@ -680,6 +678,12 @@ private Composite createInputPanel(Composite parent) {
680678
return panel;
681679
}
682680

681+
private void updateFindString() {
682+
if (okToUse(fFindField)) {
683+
findReplaceLogic.setFindString(fFindField.getText());
684+
}
685+
}
686+
683687
/**
684688
* Creates the functional options part of the options defining section of the
685689
* find replace dialog.
@@ -708,6 +712,7 @@ private Composite createOptionsGroup(Composite parent) {
708712
public void widgetSelected(SelectionEvent e) {
709713
setupFindReplaceLogic();
710714
storeSettings();
715+
updateFindString();
711716
}
712717

713718
@Override
@@ -745,6 +750,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
745750
public void widgetSelected(SelectionEvent e) {
746751
setupFindReplaceLogic();
747752
storeSettings();
753+
updateFindString();
748754
}
749755

750756
@Override
@@ -770,7 +776,7 @@ public void widgetSelected(SelectionEvent e) {
770776
storeSettings();
771777
updateButtonState();
772778
setContentAssistsEnablement(newState);
773-
fIncrementalCheckBox.setEnabled(findReplaceLogic.isAvailable(SearchOptions.INCREMENTAL));
779+
updateFindString();
774780
}
775781
});
776782
storeButtonWithMnemonicInMap(fIsRegExCheckBox);
@@ -779,9 +785,9 @@ public void widgetSelected(SelectionEvent e) {
779785
@Override
780786
public void widgetSelected(SelectionEvent e) {
781787
updateButtonState();
788+
updateFindString();
782789
}
783790
});
784-
fIncrementalCheckBox.setEnabled(findReplaceLogic.isAvailable(SearchOptions.INCREMENTAL));
785791
return panel;
786792
}
787793

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,25 @@ public void testFindWithWholeWordEnabledWithMultipleWords() {
212212
@Test
213213
public void testRegExSearch() {
214214
initializeTextViewerWithFindReplaceUI("abc");
215-
dialog.select(SearchOptions.REGEX);
215+
dialog.select(SearchOptions.INCREMENTAL);
216216
dialog.setFindText("(a|bc)");
217+
dialog.select(SearchOptions.REGEX);
217218

218219
IFindReplaceTarget target= getFindReplaceTarget();
219-
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
220220
assertEquals(0, (target.getSelection()).x);
221221
assertEquals(1, (target.getSelection()).y);
222222

223223
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
224224
assertEquals(1, (target.getSelection()).x);
225225
assertEquals(2, (target.getSelection()).y);
226+
227+
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
228+
assertEquals(0, (target.getSelection()).x);
229+
assertEquals(1, (target.getSelection()).y);
230+
231+
dialog.setFindText("b|c");
232+
assertEquals(1, (target.getSelection()).x);
233+
assertEquals(1, (target.getSelection()).y);
226234
}
227235

228236
@Test

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ public void testSearchBackwardsWithRegEx() {
160160

161161
OverlayAccess dialog= getDialog();
162162
dialog.select(SearchOptions.REGEX);
163-
dialog.setFindText("text"); // with RegEx enabled, there is no incremental search!
164-
dialog.pressSearch(true);
163+
dialog.setFindText("text");
165164
assertThat(target.getSelection().y, is(4));
166165
dialog.pressSearch(true);
167166
assertThat(target.getSelection().x, is("text ".length()));

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,6 @@ public void testReplaceAndFindAfterInitializingFindWithSelectedString() {
163163
assertEquals(4, (target.getSelection()).y);
164164
}
165165

166-
@Test
167-
public void testIncrementalSearchOnlyEnabledWhenAllowed() {
168-
initializeTextViewerWithFindReplaceUI("text text text");
169-
DialogAccess dialog= getDialog();
170-
171-
dialog.select(SearchOptions.INCREMENTAL);
172-
dialog.select(SearchOptions.REGEX);
173-
174-
dialog.assertSelected(SearchOptions.INCREMENTAL);
175-
dialog.assertDisabled(SearchOptions.INCREMENTAL);
176-
}
177-
178166
/*
179167
* Test for https://github.com/eclipse-platform/eclipse.platform.ui/pull/1805#pullrequestreview-1993772378
180168
*/
@@ -191,15 +179,6 @@ public void testIncrementalSearchOptionRecoveredCorrectly() {
191179
dialog= getDialog();
192180
dialog.assertSelected(SearchOptions.INCREMENTAL);
193181
dialog.assertEnabled(SearchOptions.INCREMENTAL);
194-
195-
dialog.select(SearchOptions.REGEX);
196-
dialog.assertSelected(SearchOptions.INCREMENTAL);
197-
dialog.assertDisabled(SearchOptions.INCREMENTAL);
198-
199-
reopenFindReplaceUIForTextViewer();
200-
dialog= getDialog();
201-
dialog.assertSelected(SearchOptions.INCREMENTAL);
202-
dialog.assertDisabled(SearchOptions.INCREMENTAL);
203182
}
204183

205184
@Test
@@ -225,4 +204,22 @@ public void testFindWithWholeWordEnabledWithMultipleWordsNotIncremental() {
225204
assertEquals(0, (target.getSelection()).x);
226205
assertEquals(dialog.getFindText().length(), (target.getSelection()).y);
227206
}
207+
208+
@Test
209+
public void testRegExSearch_nonIncremental() {
210+
initializeTextViewerWithFindReplaceUI("abc");
211+
DialogAccess dialog= getDialog();
212+
dialog.setFindText("(a|bc)");
213+
dialog.select(SearchOptions.REGEX);
214+
215+
IFindReplaceTarget target= getFindReplaceTarget();
216+
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
217+
assertEquals(0, (target.getSelection()).x);
218+
assertEquals(1, (target.getSelection()).y);
219+
220+
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
221+
assertEquals(1, (target.getSelection()).x);
222+
assertEquals(2, (target.getSelection()).y);
223+
}
224+
228225
}

0 commit comments

Comments
 (0)