Skip to content

Commit

Permalink
Replace button in find dialog gets enabled with regular expressions
Browse files Browse the repository at this point in the history
"Replace" button in find dialog did not get enabled when "Regular
expressions" checkbox was set.
  • Loading branch information
tobias-melcher committed Jan 23, 2025
1 parent 4a38dc8 commit 1cddad7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ private void activateInFindReplaceLogicIf(SearchOptions option, boolean shouldAc
private void decorate() {
if (fIsRegExCheckBox.getSelection()) {
regexOk = SearchDecoration.validateRegex(fFindField.getText(), fFindFieldDecoration);
updateButtonState(regexOk);
updateButtonState(!regexOk);

} else {
fFindFieldDecoration.hide();
Expand Down Expand Up @@ -1406,6 +1406,7 @@ private void assignIDs() {
fReplaceSelectionButton.setData(ID_DATA_KEY, "replaceOne");
fReplaceFindButton.setData(ID_DATA_KEY, "replaceFindOne");
fReplaceAllButton.setData(ID_DATA_KEY, "replaceAll");
fFindNextButton.setData(ID_DATA_KEY, "findNext");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class DialogAccess implements IFindReplaceUIAccess {

private final Button replaceAllButton;

private final Button findNextButton;

DialogAccess(IFindReplaceTarget findReplaceTarget, Dialog findReplaceDialog) {
this.findReplaceTarget= findReplaceTarget;
this.findReplaceDialog= findReplaceDialog;
Expand All @@ -89,6 +91,7 @@ class DialogAccess implements IFindReplaceUIAccess {
replaceButton= widgetExtractor.findButton("replaceOne");
replaceFindButton= widgetExtractor.findButton("replaceFindOne");
replaceAllButton= widgetExtractor.findButton("replaceAll");
findNextButton= widgetExtractor.findButton("findNext");
}

void restoreInitialConfiguration() {
Expand Down Expand Up @@ -205,6 +208,10 @@ public String getSelectedFindText() {
return findCombo.getText().substring(selection.x, selection.y);
}

public Button getReplaceButton() {
return replaceButton;
}

public Combo getFindCombo() {
return findCombo;
}
Expand All @@ -219,6 +226,10 @@ public void performReplace() {
replaceButton.notifyListeners(SWT.Selection, null);
}

public void performFindNext() {
findNextButton.notifyListeners(SWT.Selection, null);
}

@Override
public void performReplaceAndFind() {
replaceFindButton.notifyListeners(SWT.Selection, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,17 @@ public void testRegExSearch_nonIncremental() {
assertEquals(2, (target.getSelection()).y);
}

@Test
public void testReplaceButtonEnabledWithRegexSearched() {
initializeTextViewerWithFindReplaceUI("one two three");

DialogAccess dialog= getDialog();
dialog.setFindText("two");
dialog.select(SearchOptions.REGEX);
dialog.setReplaceText("two2");
dialog.performFindNext();

assertTrue(dialog.getReplaceButton().isEnabled());
}

}

0 comments on commit 1cddad7

Please sign in to comment.