@@ -86,16 +86,16 @@ export default function(CodeMirror) {
86
86
87
87
var upArrow = dialog . getElementsByClassName ( "up-arrow" ) [ 0 ] ;
88
88
CodeMirror . on ( upArrow , "click" , function ( ) {
89
+ cm . focus ( ) ;
89
90
CodeMirror . commands . findPrev ( cm ) ;
90
91
searchField . blur ( ) ;
91
- cm . focus ( ) ;
92
92
} ) ;
93
93
94
94
var downArrow = dialog . getElementsByClassName ( "down-arrow" ) [ 0 ] ;
95
95
CodeMirror . on ( downArrow , "click" , function ( ) {
96
+ cm . focus ( ) ;
96
97
CodeMirror . commands . findNext ( cm ) ;
97
98
searchField . blur ( ) ;
98
- cm . focus ( ) ;
99
99
} ) ;
100
100
101
101
var regexpButton = dialog . getElementsByClassName ( "CodeMirror-regexp-button" ) [ 0 ] ;
@@ -401,18 +401,20 @@ export default function(CodeMirror) {
401
401
402
402
// TODO: This will need updating if replace is implemented
403
403
function replace ( cm , all ) {
404
+ const state = getSearchState ( cm ) ;
404
405
var prevDialog = document . getElementsByClassName ( "CodeMirror-dialog" ) [ 0 ] ;
405
406
if ( prevDialog ) {
406
407
clearSearch ( cm ) ;
407
408
prevDialog . parentNode . removeChild ( prevDialog ) ;
408
409
cm . focus ( ) ;
409
410
}
410
411
if ( cm . getOption ( "readOnly" ) ) return ;
411
- var query = cm . getSelection ( ) || getSearchState ( cm ) . lastQuery ;
412
+ var query = cm . getSelection ( ) || state . lastQuery ;
412
413
var dialogText = all ? "Replace all:" : "Replace:"
413
414
dialog ( cm , dialogText + replaceQueryDialog , dialogText , query , function ( query ) {
414
415
if ( ! query ) return ;
415
- query = parseQuery ( query ) ;
416
+ query = parseQuery ( query , state ) ;
417
+
416
418
dialog ( cm , replacementQueryDialog , "Replace with:" , "" , function ( text ) {
417
419
text = parseString ( text )
418
420
if ( all ) {
@@ -451,6 +453,6 @@ export default function(CodeMirror) {
451
453
CodeMirror . commands . findNext = doSearch ;
452
454
CodeMirror . commands . findPrev = function ( cm ) { doSearch ( cm , true ) ; } ;
453
455
CodeMirror . commands . clearSearch = clearSearch ;
454
- // CodeMirror.commands.replace = replace;
455
- // CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
456
+ CodeMirror . commands . replace = replace ;
457
+ CodeMirror . commands . replaceAll = function ( cm ) { replace ( cm , true ) ; } ;
456
458
} ;
0 commit comments