Skip to content

Commit 3bc7e6f

Browse files
committed
FindReplaceDialog: preserve replace button enablement #2863
When typing into the replace input field of the FindReplaceDialog, the replace buttons currently become disabled in case incremental search is not activated. This requires another find to be explicitly triggered. The reason is that button enablement handling for changes in the find and replace input fields have erroneously been merged. This change corrects the enablement calculation for changes to the replace input field by reverting to the original separation between how buttons are enabled based on changes in the find input and in the replace input field. Tests did not find the issue as they did not check for enablement of the according buttons. This change also corrects that. Fixes #2863
1 parent b6af990 commit 3bc7e6f

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ public void modifyText(ModifyEvent e) {
154154
fFindField.addModifyListener(event -> {
155155
decorate();
156156
});
157-
158-
updateButtonState(!findReplaceLogic.isActive(SearchOptions.INCREMENTAL));
159157
}
160158
}
161159

@@ -629,9 +627,6 @@ public void widgetDefaultSelected(SelectionEvent e) {
629627
* @return the input panel
630628
*/
631629
private Composite createInputPanel(Composite parent) {
632-
633-
ModifyListener listener = e -> updateButtonState();
634-
635630
Composite panel = new Composite(parent, SWT.NULL);
636631
GridLayout layout = new GridLayout();
637632
layout.numColumns = 2;
@@ -652,7 +647,10 @@ private Composite createInputPanel(Composite parent) {
652647
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
653648
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
654649
addDecorationMargin(fFindField);
655-
fFindModifyListener = new InputModifyListener(this::updateFindString);
650+
fFindModifyListener = new InputModifyListener(() -> {
651+
updateFindString();
652+
updateButtonState(!findReplaceLogic.isActive(SearchOptions.INCREMENTAL));
653+
});
656654
fFindField.addModifyListener(fFindModifyListener);
657655

658656
fReplaceLabel = new Label(panel, SWT.LEFT);
@@ -671,9 +669,9 @@ private Composite createInputPanel(Composite parent) {
671669
if (okToUse(fReplaceField)) {
672670
findReplaceLogic.setReplaceString(fReplaceField.getText());
673671
}
672+
updateButtonState();
674673
});
675674
fReplaceField.addModifyListener(fReplaceModifyListener);
676-
fReplaceField.addModifyListener(listener);
677675

678676
return panel;
679677
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ public void testRegExSearch() {
236236
@Test
237237
public void testSimpleReplace() {
238238
initializeTextViewerWithFindReplaceUI("ABCD ABCD ABCD");
239+
dialog.select(SearchOptions.INCREMENTAL);
240+
239241
dialog.setFindText("ABCD");
240242
dialog.setReplaceText("abcd");
241243
dialog.performReplace();

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,29 @@ public Combo getFindCombo() {
218218

219219
@Override
220220
public void performReplaceAll() {
221-
replaceAllButton.notifyListeners(SWT.Selection, null);
221+
if (replaceAllButton.getEnabled()) {
222+
replaceAllButton.notifyListeners(SWT.Selection, null);
223+
}
222224
}
223225

224226
@Override
225227
public void performReplace() {
226-
replaceButton.notifyListeners(SWT.Selection, null);
228+
if (replaceButton.getEnabled()) {
229+
replaceButton.notifyListeners(SWT.Selection, null);
230+
}
227231
}
228232

229233
public void performFindNext() {
230-
findNextButton.notifyListeners(SWT.Selection, null);
234+
if (findNextButton.getEnabled()) {
235+
findNextButton.notifyListeners(SWT.Selection, null);
236+
}
231237
}
232238

233239
@Override
234240
public void performReplaceAndFind() {
235-
replaceFindButton.notifyListeners(SWT.Selection, null);
241+
if (replaceFindButton.getEnabled()) {
242+
replaceFindButton.notifyListeners(SWT.Selection, null);
243+
}
236244
}
237245

238246
@Override

0 commit comments

Comments
 (0)