Skip to content

Commit fe8a805

Browse files
author
Maximilian Wittmer
authored
FindReplaceLogic: update incremental base location even with RegEx (#2108)
Update the incremental Base location even if RegEx is enabled and incremental search is disabled. Once RegEx is disabled, the incremental base location is thus still valid. fixes #1915
1 parent 0d6c27b commit fe8a805

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ public boolean isRegExSearchAvailableAndActive() {
138138

139139
@Override
140140
public void resetIncrementalBaseLocation() {
141-
if (target != null && isActive(SearchOptions.INCREMENTAL) && !isRegExSearchAvailableAndActive()) {
141+
if (target != null && shouldInitIncrementalBaseLocation()) {
142142
incrementalBaseLocation = target.getSelection();
143143
} else {
144144
incrementalBaseLocation = new Point(0, 0);
145145
}
146146
}
147147

148148
public boolean shouldInitIncrementalBaseLocation() {
149-
return isActive(SearchOptions.INCREMENTAL) && !isActive(SearchOptions.REGEX);
149+
return isActive(SearchOptions.INCREMENTAL);
150150
}
151151

152152
/**

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,33 @@ public void testPerformIncrementalSearch() {
695695
assertThat(findReplaceLogic.getTarget().getSelection().y, is(4));
696696
}
697697

698+
@Test
699+
public void testIncrementBaseLocationWithRegEx() {
700+
TextViewer textViewer= setupTextViewer("Test Test Test Test Test");
701+
IFindReplaceLogic findReplaceLogic= setupFindReplaceLogicObject(textViewer);
702+
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
703+
findReplaceLogic.activate(SearchOptions.FORWARD);
704+
705+
findReplaceLogic.performSearch("Test");
706+
assertThat(findReplaceLogic.getTarget().getSelection(), is(new Point(0, 4)));
707+
708+
findReplaceLogic.activate(SearchOptions.REGEX);
709+
findReplaceLogic.deactivate(SearchOptions.INCREMENTAL);
710+
findReplaceLogic.performSearch("Test");
711+
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
712+
assertThat(findReplaceLogic.getTarget().getSelection(), is(new Point(5, 4)));
713+
findReplaceLogic.deactivate(SearchOptions.INCREMENTAL);
714+
findReplaceLogic.performSearch("Test");
715+
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
716+
assertThat(findReplaceLogic.getTarget().getSelection(), is(new Point(10, 4)));
717+
findReplaceLogic.deactivate(SearchOptions.REGEX);
718+
719+
findReplaceLogic.performSearch("Test");
720+
assertThat(findReplaceLogic.getTarget().getSelection(), is(new Point(15, 4)));
721+
findReplaceLogic.performSearch("Test");
722+
assertThat(findReplaceLogic.getTarget().getSelection(), is(new Point(15, 4)));
723+
}
724+
698725
private void expectStatusEmpty(IFindReplaceLogic findReplaceLogic) {
699726
assertThat(findReplaceLogic.getStatus(), instanceOf(NoStatus.class));
700727
}

0 commit comments

Comments
 (0)