5050public  class  FindReplaceLogic  implements  IFindReplaceLogic  {
5151	private  IFindReplaceStatus  status ;
5252	private  IFindReplaceTarget  target ;
53- 	private  IRegion  oldScope ;
5453	private  Point  incrementalBaseLocation ;
5554
5655	private  boolean  isTargetSupportingRegEx ;
@@ -65,15 +64,15 @@ public void activate(SearchOptions searchOption) {
6564
6665		switch  (searchOption ) {
6766		case  GLOBAL :
68- 			useSelectedLines ( false );
67+ 			unsetSearchScope ( );
6968			break ;
7069		case  FORWARD :
7170		case  INCREMENTAL :
7271			if  (shouldInitIncrementalBaseLocation ()) {
7372				initIncrementalBaseLocation ();
7473			}
7574			break ;
76- 			 // $CASES-OMITTED$ 
75+ 		// $CASES-OMITTED$ 
7776		default :
7877			break ;
7978		}
@@ -86,7 +85,7 @@ public void deactivate(SearchOptions searchOption) {
8685		}
8786
8887		if  (searchOption  == SearchOptions .GLOBAL ) {
89- 			useSelectedLines ( true );
88+ 			initializeSearchScope ( );
9089		}
9190
9291		if  (searchOption  == SearchOptions .FORWARD  && shouldInitIncrementalBaseLocation ()) {
@@ -152,10 +151,8 @@ public boolean shouldInitIncrementalBaseLocation() {
152151	/** 
153152	 * Tells the dialog to perform searches only in the scope given by the actually 
154153	 * selected lines. 
155- 	 * 
156- 	 * @param selectedLines <code>true</code> if selected lines should be used 
157154	 */ 
158- 	private  void  useSelectedLines ( boolean   selectedLines ) {
155+ 	private  void  initializeSearchScope ( ) {
159156		if  (shouldInitIncrementalBaseLocation ()) {
160157			initIncrementalBaseLocation ();
161158		}
@@ -166,25 +163,27 @@ private void useSelectedLines(boolean selectedLines) {
166163
167164		IFindReplaceTargetExtension  extensionTarget  = (IFindReplaceTargetExtension ) target ;
168165
169- 		if  (selectedLines ) {
166+ 		IRegion  scope ;
167+ 		Point  lineSelection  = extensionTarget .getLineSelection ();
168+ 		scope  = new  Region (lineSelection .x , lineSelection .y );
170169
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 ();
179171
180- 			int  offset  = isActive (SearchOptions .FORWARD ) ? scope .getOffset () : scope .getOffset () + scope .getLength ();
172+ 		extensionTarget .setSelection (offset , 0 );
173+ 		extensionTarget .setScope (scope );
174+ 	}
181175
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 ;
187182		}
183+ 
184+ 		IFindReplaceTargetExtension  extensionTarget  = (IFindReplaceTargetExtension ) target ;
185+ 
186+ 		extensionTarget .setScope (null );
188187	}
189188
190189	/** 
0 commit comments