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 8d2175d6a79..8099d514bb2 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 @@ -326,9 +326,13 @@ private boolean replaceSelection(String replaceString) { @Override public boolean performSearch(String findString) { + return performSearch(findString, true); + } + + private boolean performSearch(String findString, boolean validateSearchOptions) { resetStatus(); - if (isActive(SearchOptions.INCREMENTAL) && !isIncrementalSearchAvailable()) { + if (validateSearchOptions && (isActive(SearchOptions.INCREMENTAL) && !isIncrementalSearchAvailable())) { return false; // Do nothing if search options are not compatible } boolean somethingFound = false; @@ -543,7 +547,7 @@ private int calculateFindBeginningOffset() { public boolean performReplaceAndFind(String findString, String replaceString) { resetStatus(); if (performSelectAndReplace(findString, replaceString)) { - performSearch(findString); + performSearch(findString, false); return true; } return false; @@ -553,7 +557,7 @@ public boolean performReplaceAndFind(String findString, String replaceString) { public boolean performSelectAndReplace(String findString, String replaceString) { resetStatus(); if (!isFindStringSelected(findString)) { - performSearch(findString); + performSearch(findString, false); } if (getStatus().wasSuccessful()) { return replaceSelection(replaceString); diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java index f79442b394e..67181162ae6 100644 --- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java +++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java @@ -351,6 +351,21 @@ public void testPerformReplaceAndFindRegEx() { findReplaceLogic.activate(SearchOptions.FORWARD); findReplaceLogic.activate(SearchOptions.REGEX); + executeReplaceAndFindRegExTest(textViewer, findReplaceLogic); + } + + @Test + public void testPerformReplaceAndFindRegEx_incrementalActive() { + TextViewer textViewer= setupTextViewer("HelloWorld!!"); + IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(textViewer); + findReplaceLogic.activate(SearchOptions.FORWARD); + findReplaceLogic.activate(SearchOptions.INCREMENTAL); + findReplaceLogic.activate(SearchOptions.REGEX); + + executeReplaceAndFindRegExTest(textViewer, findReplaceLogic); + } + + private void executeReplaceAndFindRegExTest(TextViewer textViewer, IFindReplaceLogic findReplaceLogic) { boolean status= findReplaceLogic.performReplaceAndFind("<(\\w*)>", " "); assertTrue(status); assertThat(textViewer.getDocument().get(), equalTo("Hello World!!")); @@ -374,6 +389,22 @@ public void testPerformReplaceAndFindRegEx() { expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH); } + @Test + public void testPerformSearchAndReplaceRegEx_incrementalActive() { + TextViewer textViewer= setupTextViewer("some text"); + IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(textViewer); + findReplaceLogic.activate(SearchOptions.FORWARD); + findReplaceLogic.activate(SearchOptions.INCREMENTAL); + findReplaceLogic.activate(SearchOptions.REGEX); + + findReplaceLogic.performSearch("text"); + textViewer.setSelectedRange(0, 0); + + findReplaceLogic.performSelectAndReplace("text", ""); + + assertEquals("some ", textViewer.getDocument().get()); + } + @Test public void testPerformSelectAllForward() { TextViewer textViewer= setupTextViewer("AbAbAbAb");