@@ -28,22 +28,6 @@ export default function(CodeMirror) {
2828 } } ;
2929 }
3030
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-
4731 function SearchState ( ) {
4832 this . posFrom = this . posTo = this . lastQuery = this . query = null ;
4933 this . overlay = null ;
@@ -182,7 +166,7 @@ export default function(CodeMirror) {
182166 replaceDiv . style . height = replaceDivHeightClosed ;
183167 toggleReplaceBtnDiv . style . height = toggleButtonHeightClosed ;
184168 showReplaceButton . style . height = toggleButtonHeightClosed ;
185- showReplaceButton . innerHTML = "▶ " ;
169+ showReplaceButton . innerHTML = "► " ;
186170 }
187171 }
188172
@@ -279,49 +263,6 @@ export default function(CodeMirror) {
279263 else f ( prompt ( shortText , deflt ) ) ;
280264 }
281265
282- var lastSelectedIndex = 0 ;
283- function confirmDialog ( cm , text , shortText , fs ) {
284- if ( cm . openConfirm ) cm . openConfirm ( text , fs ) ;
285- else if ( confirm ( shortText ) ) fs [ 0 ] ( ) ;
286-
287- var dialog = document . getElementsByClassName ( "CodeMirror-dialog" ) [ 0 ] ;
288- var buttons = dialog . getElementsByTagName ( "button" ) ;
289- buttons [ lastSelectedIndex ] . focus ( ) ;
290- for ( var i = 0 ; i < buttons . length ; i += 1 ) {
291- ( function ( index ) {
292- var button = buttons [ index ] ;
293- button . addEventListener ( "focus" , function ( e ) {
294- lastSelectedIndex = index === buttons . length - 1 ? 0 : index ;
295- } ) ;
296- button . addEventListener ( "keyup" , function ( e ) {
297- if ( e . keyCode === 37 ) { // arrow left
298- var prevButton = index === 0 ? buttons . length - 1 : index - 1 ;
299- buttons [ prevButton ] . focus ( ) ;
300- }
301- if ( e . keyCode === 39 ) { // arrow right
302- var nextButton = index === buttons . length - 1 ? 0 : index + 1 ;
303- buttons [ nextButton ] . focus ( ) ;
304- }
305- if ( e . keyCode === 27 ) { // esc
306- // Remove replace-overlay & focus on the editor.
307- const state = getSearchState ( cm ) ;
308- cm . removeOverlay ( state . overlay , state . caseInsensitive ) ;
309- cm . focus ( ) ;
310- }
311- } ) ;
312- button . addEventListener ( "click" , function ( ) {
313- if ( index === buttons . length - 1 ) { // "done"
314- lastSelectedIndex = 0 ;
315- // Remove replace-overlay & focus on the editor.
316- const state = getSearchState ( cm ) ;
317- cm . removeOverlay ( state . overlay , state . caseInsensitive ) ;
318- cm . focus ( ) ;
319- }
320- } )
321- } ) ( i ) ;
322- }
323- }
324-
325266 function parseString ( string ) {
326267 return string . replace ( / \\ ( .) / g, function ( _ , ch ) {
327268 if ( ch == "n" ) return "\n"
@@ -477,79 +418,6 @@ export default function(CodeMirror) {
477418 } ) ;
478419 }
479420
480- function replace ( cm , queryText , withText , all ) {
481- if ( ! queryText ) return ;
482- const state = getSearchState ( cm ) ;
483- var prevDialog = document . getElementsByClassName ( "CodeMirror-dialog" ) [ 0 ] ;
484- if ( prevDialog ) {
485- clearSearch ( cm ) ;
486- }
487- prevDialog . parentNode . removeChild ( prevDialog ) ;
488- cm . focus ( ) ;
489- if ( cm . getOption ( "readOnly" ) ) return ;
490- var query = parseQuery ( queryText , state ) ;
491- if ( all ) {
492- replaceAll ( cm , query , withText )
493- } else {
494- clearSearch ( cm ) ;
495- var cursor = getSearchCursor ( cm , query , cm . getCursor ( "from" ) ) ;
496- var advance = function ( ) {
497- var start = cursor . from ( ) , match ;
498- if ( ! ( match = cursor . findNext ( ) ) ) {
499- cursor = getSearchCursor ( cm , query ) ;
500- if ( ! ( match = cursor . findNext ( ) ) ||
501- ( start && cursor . from ( ) . line == start . line && cursor . from ( ) . ch == start . ch ) ) return ;
502- }
503-
504- // Add an overlay to the text to be replaced.
505- cm . removeOverlay ( state . overlay , state . caseInsensitive ) ;
506- var flag = false ;
507- state . overlay = replaceOverlay ( cursor . from ( ) , cursor . to ( ) , flag ) ;
508- cm . addOverlay ( state . overlay ) ;
509-
510- cm . scrollIntoView ( { from : cursor . from ( ) , to : cursor . to ( ) } , 60 ) ;
511- confirmDialog ( cm , doReplaceConfirm , "Replace?" ,
512- [ function ( ) { doReplace ( match ) ; } , advance ,
513- function ( ) { replaceAll ( cm , query , withText ) } ] ) ;
514- } ;
515- var doReplace = function ( match ) {
516- cursor . replace ( typeof query == "string" ? withText :
517- withText . replace ( / \$ ( \d ) / g, function ( _ , i ) { return match [ i ] ; } ) ) ;
518- advance ( ) ;
519- } ;
520- advance ( ) ;
521- }
522- }
523-
524- var doReplaceConfirm = `
525- <div class="CodeMirror-replace-options">
526- <button
527- title="Replace"
528- aria-label="Replace"
529- >
530- Replace
531- </button>
532- <button
533- title="Skip"
534- aria-label="Skip"
535- >
536- Skip
537- </button>
538- <button
539- title="Replace All"
540- aria-label="Replace All"
541- >
542- Replace All
543- </button>
544- <button
545- title="Stop"
546- aria-label="Stop"
547- >
548- Stop
549- </button>
550- </div>
551- ` ;
552-
553421 var queryDialog = `
554422 <div class="CodeMirror-find-popup-container">
555423 <div class="Toggle-replace-btn-div">
@@ -652,5 +520,4 @@ export default function(CodeMirror) {
652520 CodeMirror . commands . findPrev = function ( cm ) { doFindAndReplace ( cm , true ) ; } ;
653521 CodeMirror . commands . clearSearch = clearSearch ;
654522 CodeMirror . commands . replace = function ( cm ) { doFindAndReplace ( cm , false , true , false , true , true ) ; } ;
655- CodeMirror . commands . replaceAll = function ( cm ) { doFindAndReplace ( cm , false , true , false , true , true ) ; } ;
656523} ;
0 commit comments