diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java index a6a69c6c3b4..53640118526 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java @@ -132,12 +132,11 @@ private void resetStatus() { @Override public boolean isAvailable(SearchOptions searchOption) { switch (searchOption) { - case INCREMENTAL: - return !isAvailableAndActive(SearchOptions.REGEX); case REGEX: return isTargetSupportingRegEx; case WHOLE_WORD: return !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString); + case INCREMENTAL: case CASE_SENSITIVE: case FORWARD: case GLOBAL: diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java index ee8ea79abb4..99be619dcd9 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java @@ -589,6 +589,7 @@ public void widgetSelected(SelectionEvent e) { return; } findReplaceLogic.activate(SearchOptions.GLOBAL); + updateFindString(); } @Override @@ -608,6 +609,7 @@ public void widgetSelected(SelectionEvent e) { return; } findReplaceLogic.deactivate(SearchOptions.GLOBAL); + updateFindString(); } @Override @@ -650,11 +652,7 @@ private Composite createInputPanel(Composite parent) { ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true); setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false); addDecorationMargin(fFindField); - fFindModifyListener = new InputModifyListener(() -> { - if (okToUse(fFindField)) { - findReplaceLogic.setFindString(fFindField.getText()); - } - }); + fFindModifyListener = new InputModifyListener(this::updateFindString); fFindField.addModifyListener(fFindModifyListener); fReplaceLabel = new Label(panel, SWT.LEFT); @@ -680,6 +678,12 @@ private Composite createInputPanel(Composite parent) { return panel; } + private void updateFindString() { + if (okToUse(fFindField)) { + findReplaceLogic.setFindString(fFindField.getText()); + } + } + /** * Creates the functional options part of the options defining section of the * find replace dialog. @@ -708,6 +712,7 @@ private Composite createOptionsGroup(Composite parent) { public void widgetSelected(SelectionEvent e) { setupFindReplaceLogic(); storeSettings(); + updateFindString(); } @Override @@ -745,6 +750,7 @@ public void widgetDefaultSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) { setupFindReplaceLogic(); storeSettings(); + updateFindString(); } @Override @@ -770,7 +776,7 @@ public void widgetSelected(SelectionEvent e) { storeSettings(); updateButtonState(); setContentAssistsEnablement(newState); - fIncrementalCheckBox.setEnabled(findReplaceLogic.isAvailable(SearchOptions.INCREMENTAL)); + updateFindString(); } }); storeButtonWithMnemonicInMap(fIsRegExCheckBox); @@ -779,9 +785,9 @@ public void widgetSelected(SelectionEvent e) { @Override public void widgetSelected(SelectionEvent e) { updateButtonState(); + updateFindString(); } }); - fIncrementalCheckBox.setEnabled(findReplaceLogic.isAvailable(SearchOptions.INCREMENTAL)); return panel; } diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java index f943211d545..aaff1aa04d5 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java @@ -212,17 +212,25 @@ public void testFindWithWholeWordEnabledWithMultipleWords() { @Test public void testRegExSearch() { initializeTextViewerWithFindReplaceUI("abc"); - dialog.select(SearchOptions.REGEX); + dialog.select(SearchOptions.INCREMENTAL); dialog.setFindText("(a|bc)"); + dialog.select(SearchOptions.REGEX); IFindReplaceTarget target= getFindReplaceTarget(); - dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false); assertEquals(0, (target.getSelection()).x); assertEquals(1, (target.getSelection()).y); dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false); assertEquals(1, (target.getSelection()).x); assertEquals(2, (target.getSelection()).y); + + dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false); + assertEquals(0, (target.getSelection()).x); + assertEquals(1, (target.getSelection()).y); + + dialog.setFindText("b|c"); + assertEquals(1, (target.getSelection()).x); + assertEquals(1, (target.getSelection()).y); } @Test diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java index c19210ac315..7e80fc64a10 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java @@ -160,8 +160,7 @@ public void testSearchBackwardsWithRegEx() { OverlayAccess dialog= getDialog(); dialog.select(SearchOptions.REGEX); - dialog.setFindText("text"); // with RegEx enabled, there is no incremental search! - dialog.pressSearch(true); + dialog.setFindText("text"); assertThat(target.getSelection().y, is(4)); dialog.pressSearch(true); assertThat(target.getSelection().x, is("text ".length())); diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceDialogTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceDialogTest.java index 5e846f760de..e802945dee6 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceDialogTest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceDialogTest.java @@ -163,18 +163,6 @@ public void testReplaceAndFindAfterInitializingFindWithSelectedString() { assertEquals(4, (target.getSelection()).y); } - @Test - public void testIncrementalSearchOnlyEnabledWhenAllowed() { - initializeTextViewerWithFindReplaceUI("text text text"); - DialogAccess dialog= getDialog(); - - dialog.select(SearchOptions.INCREMENTAL); - dialog.select(SearchOptions.REGEX); - - dialog.assertSelected(SearchOptions.INCREMENTAL); - dialog.assertDisabled(SearchOptions.INCREMENTAL); - } - /* * Test for https://github.com/eclipse-platform/eclipse.platform.ui/pull/1805#pullrequestreview-1993772378 */ @@ -191,15 +179,6 @@ public void testIncrementalSearchOptionRecoveredCorrectly() { dialog= getDialog(); dialog.assertSelected(SearchOptions.INCREMENTAL); dialog.assertEnabled(SearchOptions.INCREMENTAL); - - dialog.select(SearchOptions.REGEX); - dialog.assertSelected(SearchOptions.INCREMENTAL); - dialog.assertDisabled(SearchOptions.INCREMENTAL); - - reopenFindReplaceUIForTextViewer(); - dialog= getDialog(); - dialog.assertSelected(SearchOptions.INCREMENTAL); - dialog.assertDisabled(SearchOptions.INCREMENTAL); } @Test @@ -225,4 +204,22 @@ public void testFindWithWholeWordEnabledWithMultipleWordsNotIncremental() { assertEquals(0, (target.getSelection()).x); assertEquals(dialog.getFindText().length(), (target.getSelection()).y); } + + @Test + public void testRegExSearch_nonIncremental() { + initializeTextViewerWithFindReplaceUI("abc"); + DialogAccess dialog= getDialog(); + dialog.setFindText("(a|bc)"); + dialog.select(SearchOptions.REGEX); + + IFindReplaceTarget target= getFindReplaceTarget(); + dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false); + assertEquals(0, (target.getSelection()).x); + assertEquals(1, (target.getSelection()).y); + + dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false); + assertEquals(1, (target.getSelection()).x); + assertEquals(2, (target.getSelection()).y); + } + }