50
50
public class FindReplaceLogic implements IFindReplaceLogic {
51
51
private IFindReplaceStatus status ;
52
52
private IFindReplaceTarget target ;
53
- private IRegion oldScope ;
54
53
private Point incrementalBaseLocation ;
55
54
56
55
private boolean isTargetSupportingRegEx ;
@@ -65,15 +64,15 @@ public void activate(SearchOptions searchOption) {
65
64
66
65
switch (searchOption ) {
67
66
case GLOBAL :
68
- useSelectedLines ( false );
67
+ unsetSearchScope ( );
69
68
break ;
70
69
case FORWARD :
71
70
case INCREMENTAL :
72
71
if (shouldInitIncrementalBaseLocation ()) {
73
72
initIncrementalBaseLocation ();
74
73
}
75
74
break ;
76
- // $CASES-OMITTED$
75
+ // $CASES-OMITTED$
77
76
default :
78
77
break ;
79
78
}
@@ -86,7 +85,7 @@ public void deactivate(SearchOptions searchOption) {
86
85
}
87
86
88
87
if (searchOption == SearchOptions .GLOBAL ) {
89
- useSelectedLines ( true );
88
+ initializeSearchScope ( );
90
89
}
91
90
92
91
if (searchOption == SearchOptions .FORWARD && shouldInitIncrementalBaseLocation ()) {
@@ -152,10 +151,8 @@ public boolean shouldInitIncrementalBaseLocation() {
152
151
/**
153
152
* Tells the dialog to perform searches only in the scope given by the actually
154
153
* selected lines.
155
- *
156
- * @param selectedLines <code>true</code> if selected lines should be used
157
154
*/
158
- private void useSelectedLines ( boolean selectedLines ) {
155
+ private void initializeSearchScope ( ) {
159
156
if (shouldInitIncrementalBaseLocation ()) {
160
157
initIncrementalBaseLocation ();
161
158
}
@@ -166,25 +163,27 @@ private void useSelectedLines(boolean selectedLines) {
166
163
167
164
IFindReplaceTargetExtension extensionTarget = (IFindReplaceTargetExtension ) target ;
168
165
169
- if (selectedLines ) {
166
+ IRegion scope ;
167
+ Point lineSelection = extensionTarget .getLineSelection ();
168
+ scope = new Region (lineSelection .x , lineSelection .y );
170
169
171
- IRegion scope ;
172
- if (oldScope == null ) {
173
- Point lineSelection = extensionTarget .getLineSelection ();
174
- scope = new Region (lineSelection .x , lineSelection .y );
175
- } else {
176
- scope = oldScope ;
177
- oldScope = null ;
178
- }
170
+ int offset = isActive (SearchOptions .FORWARD ) ? scope .getOffset () : scope .getOffset () + scope .getLength ();
179
171
180
- int offset = isActive (SearchOptions .FORWARD ) ? scope .getOffset () : scope .getOffset () + scope .getLength ();
172
+ extensionTarget .setSelection (offset , 0 );
173
+ extensionTarget .setScope (scope );
174
+ }
181
175
182
- extensionTarget .setSelection (offset , 0 );
183
- extensionTarget .setScope (scope );
184
- } else {
185
- oldScope = extensionTarget .getScope ();
186
- extensionTarget .setScope (null );
176
+ /**
177
+ * Unsets the search scope for a "Scoped"-Search.
178
+ */
179
+ private void unsetSearchScope () {
180
+ if (target == null || !(target instanceof IFindReplaceTargetExtension )) {
181
+ return ;
187
182
}
183
+
184
+ IFindReplaceTargetExtension extensionTarget = (IFindReplaceTargetExtension ) target ;
185
+
186
+ extensionTarget .setScope (null );
188
187
}
189
188
190
189
/**
0 commit comments