Skip to content

Commit 1cddad7

Browse files
Replace button in find dialog gets enabled with regular expressions
"Replace" button in find dialog did not get enabled when "Regular expressions" checkbox was set.
1 parent 4a38dc8 commit 1cddad7

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
13611361
private void decorate() {
13621362
if (fIsRegExCheckBox.getSelection()) {
13631363
regexOk = SearchDecoration.validateRegex(fFindField.getText(), fFindFieldDecoration);
1364-
updateButtonState(regexOk);
1364+
updateButtonState(!regexOk);
13651365

13661366
} else {
13671367
fFindFieldDecoration.hide();
@@ -1406,6 +1406,7 @@ private void assignIDs() {
14061406
fReplaceSelectionButton.setData(ID_DATA_KEY, "replaceOne");
14071407
fReplaceFindButton.setData(ID_DATA_KEY, "replaceFindOne");
14081408
fReplaceAllButton.setData(ID_DATA_KEY, "replaceAll");
1409+
fFindNextButton.setData(ID_DATA_KEY, "findNext");
14091410
}
14101411

14111412
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class DialogAccess implements IFindReplaceUIAccess {
7171

7272
private final Button replaceAllButton;
7373

74+
private final Button findNextButton;
75+
7476
DialogAccess(IFindReplaceTarget findReplaceTarget, Dialog findReplaceDialog) {
7577
this.findReplaceTarget= findReplaceTarget;
7678
this.findReplaceDialog= findReplaceDialog;
@@ -89,6 +91,7 @@ class DialogAccess implements IFindReplaceUIAccess {
8991
replaceButton= widgetExtractor.findButton("replaceOne");
9092
replaceFindButton= widgetExtractor.findButton("replaceFindOne");
9193
replaceAllButton= widgetExtractor.findButton("replaceAll");
94+
findNextButton= widgetExtractor.findButton("findNext");
9295
}
9396

9497
void restoreInitialConfiguration() {
@@ -205,6 +208,10 @@ public String getSelectedFindText() {
205208
return findCombo.getText().substring(selection.x, selection.y);
206209
}
207210

211+
public Button getReplaceButton() {
212+
return replaceButton;
213+
}
214+
208215
public Combo getFindCombo() {
209216
return findCombo;
210217
}
@@ -219,6 +226,10 @@ public void performReplace() {
219226
replaceButton.notifyListeners(SWT.Selection, null);
220227
}
221228

229+
public void performFindNext() {
230+
findNextButton.notifyListeners(SWT.Selection, null);
231+
}
232+
222233
@Override
223234
public void performReplaceAndFind() {
224235
replaceFindButton.notifyListeners(SWT.Selection, null);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,17 @@ public void testRegExSearch_nonIncremental() {
222222
assertEquals(2, (target.getSelection()).y);
223223
}
224224

225+
@Test
226+
public void testReplaceButtonEnabledWithRegexSearched() {
227+
initializeTextViewerWithFindReplaceUI("one two three");
228+
229+
DialogAccess dialog= getDialog();
230+
dialog.setFindText("two");
231+
dialog.select(SearchOptions.REGEX);
232+
dialog.setReplaceText("two2");
233+
dialog.performFindNext();
234+
235+
assertTrue(dialog.getReplaceButton().isEnabled());
236+
}
237+
225238
}

0 commit comments

Comments
 (0)