@@ -77,7 +77,8 @@ class BufferSearch {
7777 changedParams . wholeWord != null ||
7878 changedParams . caseSensitive != null ||
7979 changedParams . inCurrentSelection != null ||
80- ( this . findOptions . inCurrentSelection === true && ! this . editor . getSelectedBufferRange ( ) . isEqual ( this . selectedRange ) ) ) {
80+ ( this . findOptions . inCurrentSelection === true
81+ && ! selectionsEqual ( this . editor . getSelectedBufferRanges ( ) , this . selectedRanges ) ) ) {
8182 this . recreateMarkers ( ) ;
8283 }
8384 }
@@ -135,37 +136,32 @@ class BufferSearch {
135136 createMarkers ( start , end ) {
136137 let newMarkers = [ ] ;
137138 if ( this . findOptions . findPattern && this . editor ) {
138- this . selectedRange = this . editor . getSelectedBufferRange ( )
139- if ( this . findOptions . inCurrentSelection && ! this . selectedRange . isEmpty ( ) ) {
140- start = Point . max ( start , this . selectedRange . start ) ;
141- end = Point . min ( end , this . selectedRange . end ) ;
139+ this . selectedRanges = this . editor . getSelectedBufferRanges ( )
140+
141+ let searchRanges = [ ]
142+ if ( this . findOptions . inCurrentSelection ) {
143+ searchRanges . push ( ...this . selectedRanges . filter ( range => ! range . isEmpty ( ) ) )
144+ }
145+ if ( searchRanges . length === 0 ) {
146+ searchRanges . push ( Range ( start , end ) )
142147 }
143148
144149 const buffer = this . editor . getBuffer ( )
145150 const regex = this . getFindPatternRegex ( buffer . hasAstral && buffer . hasAstral ( ) )
146151 if ( regex ) {
147152 try {
148- // TODO - remove this conditional after Atom 1.25 ships
149- if ( buffer . findAndMarkAllInRangeSync ) {
150- newMarkers = this . editor . getBuffer ( ) . findAndMarkAllInRangeSync (
153+ for ( const range of searchRanges ) {
154+ const bufferMarkers = this . editor . getBuffer ( ) . findAndMarkAllInRangeSync (
151155 this . resultsMarkerLayer . bufferMarkerLayer ,
152156 regex ,
153- Range ( start , end ) ,
157+ range ,
154158 { invalidate : 'inside' }
155159 ) ;
156- for ( let i = 0 , n = newMarkers . length ; i < n ; i ++ ) {
157- newMarkers [ i ] = this . resultsMarkerLayer . getMarker ( newMarkers [ i ] . id )
160+ for ( const bufferMarker of bufferMarkers ) {
161+ newMarkers . push ( this . resultsMarkerLayer . getMarker ( bufferMarker . id ) )
158162 }
159- } else {
160- buffer . scanInRange ( regex , Range ( start , end ) , ( { range} ) => {
161- newMarkers . push ( this . createMarker ( range ) ) ;
162- } ) ;
163163 }
164164 } catch ( error ) {
165- // TODO - remove after Atom 1.25 ships.
166- if ( / R e g E x p t o o b i g $ / . test ( error . message ) ) {
167- error . message = "regular expression is too large" ;
168- }
169165 this . emitter . emit ( 'did-error' , error ) ;
170166 return false ;
171167 }
@@ -291,3 +287,16 @@ class BufferSearch {
291287 }
292288 }
293289} ;
290+
291+ function selectionsEqual ( selectionsA , selectionsB ) {
292+ if ( selectionsA . length === selectionsB . length ) {
293+ for ( let i = 0 ; i < selectionsA . length ; i ++ ) {
294+ if ( ! selectionsA [ i ] . isEqual ( selectionsB [ i ] ) ) {
295+ return false
296+ }
297+ }
298+ return true
299+ } else {
300+ return false
301+ }
302+ }
0 commit comments