@@ -28,6 +28,22 @@ export default function(CodeMirror) {
28
28
} } ;
29
29
}
30
30
31
+ function replaceOverlay ( cursorFrom , cursorTo , flag ) {
32
+ return { token : function ( stream ) {
33
+ if ( ! flag && cursorFrom . line == stream . lineOracle . line ) {
34
+ if ( stream . pos == 0 ) {
35
+ stream . pos = cursorFrom . ch ;
36
+ } else {
37
+ stream . pos = cursorTo . ch ;
38
+ flag = true ;
39
+ return 'searching' ;
40
+ }
41
+ } else {
42
+ stream . skipToEnd ( ) ;
43
+ }
44
+ } } ;
45
+ }
46
+
31
47
function SearchState ( ) {
32
48
this . posFrom = this . posTo = this . lastQuery = this . query = null ;
33
49
this . overlay = null ;
@@ -227,12 +243,19 @@ export default function(CodeMirror) {
227
243
buttons [ nextButton ] . focus ( ) ;
228
244
}
229
245
if ( e . keyCode === 27 ) { // esc
246
+ // Remove replace-overlay & focus on the editor.
247
+ const state = getSearchState ( cm ) ;
248
+ cm . removeOverlay ( state . overlay , state . caseInsensitive ) ;
230
249
cm . focus ( ) ;
231
250
}
232
251
} ) ;
233
252
button . addEventListener ( "click" , function ( ) {
234
253
if ( index === buttons . length - 1 ) { // "done"
235
254
lastSelectedIndex = 0 ;
255
+ // Remove replace-overlay & focus on the editor.
256
+ const state = getSearchState ( cm ) ;
257
+ cm . removeOverlay ( state . overlay , state . caseInsensitive ) ;
258
+ cm . focus ( ) ;
236
259
}
237
260
} )
238
261
} ) ( i ) ;
@@ -416,7 +439,13 @@ export default function(CodeMirror) {
416
439
if ( ! ( match = cursor . findNext ( ) ) ||
417
440
( start && cursor . from ( ) . line == start . line && cursor . from ( ) . ch == start . ch ) ) return ;
418
441
}
419
- cm . setSelection ( cursor . from ( ) , cursor . to ( ) ) ;
442
+
443
+ // Add an overlay to the text to be replaced.
444
+ cm . removeOverlay ( state . overlay , state . caseInsensitive ) ;
445
+ var flag = false ;
446
+ state . overlay = replaceOverlay ( cursor . from ( ) , cursor . to ( ) , flag ) ;
447
+ cm . addOverlay ( state . overlay ) ;
448
+
420
449
cm . scrollIntoView ( { from : cursor . from ( ) , to : cursor . to ( ) } , 60 ) ;
421
450
confirmDialog ( cm , doReplaceConfirm , "Replace?" ,
422
451
[ function ( ) { doReplace ( match ) ; } , advance ,
0 commit comments