@@ -82,6 +82,7 @@ function persistentDialog(cm, text, deflt, onEnter, replaceOpened, onKeyDown) {
82
82
var state = getSearchState ( cm ) ;
83
83
84
84
CodeMirror . on ( searchField , "keyup" , function ( e ) {
85
+ state . replaceStarted = false ;
85
86
if ( e . keyCode !== 13 && searchField . value . length > 1 ) { // not enter and more than 1 character to search
86
87
startSearch ( cm , getSearchState ( cm ) , searchField . value ) ;
87
88
} else if ( searchField . value . length < 1 ) {
@@ -154,30 +155,30 @@ function persistentDialog(cm, text, deflt, onEnter, replaceOpened, onKeyDown) {
154
155
}
155
156
156
157
function toggleReplace ( open ) {
157
- var replaceDivHeightOpened = "45px" , replaceDivHeightClosed = "0px" ;
158
158
var toggleButtonHeightOpened = "80px" , toggleButtonHeightClosed = "40px" ;
159
159
160
160
if ( open ) {
161
- replaceDiv . style . height = replaceDivHeightOpened ;
161
+ replaceFieldDiv . style . display = replaceControlsDiv . style . display = '' ;
162
162
toggleReplaceBtnDiv . style . height = toggleButtonHeightOpened ;
163
- showReplaceButton . style . height = toggleButtonHeightOpened ;
164
- showReplaceButton . innerHTML = triangleArrowDown ;
163
+ toggleReplaceBtn . style . height = toggleButtonHeightOpened ;
164
+ toggleReplaceBtn . innerHTML = triangleArrowDown ;
165
165
} else {
166
- replaceDiv . style . height = replaceDivHeightClosed ;
166
+ replaceFieldDiv . style . display = replaceControlsDiv . style . display = 'none' ;
167
167
toggleReplaceBtnDiv . style . height = toggleButtonHeightClosed ;
168
- showReplaceButton . style . height = toggleButtonHeightClosed ;
169
- showReplaceButton . innerHTML = triangleArrowRight ;
168
+ toggleReplaceBtn . style . height = toggleButtonHeightClosed ;
169
+ toggleReplaceBtn . innerHTML = triangleArrowRight ;
170
170
}
171
171
}
172
172
173
- var showReplaceButton = dialog . getElementsByClassName ( "CodeMirror-replace-toggle-button" ) [ 0 ] ;
174
- var toggleReplaceBtnDiv = dialog . getElementsByClassName ( "Toggle-replace-btn-div" ) [ 0 ] ;
175
- var replaceDiv = dialog . getElementsByClassName ( "CodeMirror-replace-div" ) [ 0 ] ;
173
+ var toggleReplaceBtnDiv = document . getElementById ( 'Btn-Toggle-replace-div' ) ;
174
+ var toggleReplaceBtn = document . getElementById ( 'Btn-Toggle-replace' )
175
+ var replaceFieldDiv = document . getElementById ( 'Replace-input-div' ) ;
176
+ var replaceControlsDiv = document . getElementById ( 'Replace-controls-div' ) ;
176
177
if ( replaceOpened ) {
177
178
toggleReplace ( true ) ;
178
179
}
179
- CodeMirror . on ( showReplaceButton , "click" , function ( ) {
180
- if ( replaceDiv . style . height === "0px " ) {
180
+ CodeMirror . on ( toggleReplaceBtn , "click" , function ( ) {
181
+ if ( replaceFieldDiv . style . display === "none " ) {
181
182
toggleReplace ( true ) ;
182
183
} else {
183
184
toggleReplace ( false ) ;
@@ -186,10 +187,6 @@ function persistentDialog(cm, text, deflt, onEnter, replaceOpened, onKeyDown) {
186
187
187
188
var replaceField = document . getElementById ( 'Replace-input-field' ) ;
188
189
CodeMirror . on ( replaceField , "keyup" , function ( e ) {
189
- if ( ! searchField . value ) {
190
- searchField . focus ( ) ;
191
- return ;
192
- }
193
190
var state = getSearchState ( cm ) ;
194
191
var query = parseQuery ( searchField . value , state ) ;
195
192
var withText = parseString ( replaceField . value ) ;
@@ -232,13 +229,15 @@ function persistentDialog(cm, text, deflt, onEnter, replaceOpened, onKeyDown) {
232
229
if ( match ) {
233
230
cm . setSelection ( cursor . from ( ) , cursor . to ( ) ) ;
234
231
doReplace ( match , cursor , query , withText ) ;
232
+ doReplaceButton . focus ( ) ;
235
233
}
236
234
} else {
237
235
startSearch ( cm , state , searchField . value ) ;
238
236
state . replaceStarted = true ;
239
237
cm . focus ( ) ;
240
238
CodeMirror . commands . findNext ( cm ) ;
241
239
searchField . blur ( ) ;
240
+ doReplaceButton . focus ( ) ;
242
241
}
243
242
} )
244
243
@@ -251,6 +250,9 @@ function persistentDialog(cm, text, deflt, onEnter, replaceOpened, onKeyDown) {
251
250
var state = getSearchState ( cm ) ;
252
251
var query = parseQuery ( searchField . value , state ) ;
253
252
var withText = parseString ( replaceField . value ) ;
253
+ if ( searchField . value . length > 1 ) {
254
+ state . replaceStarted = true ;
255
+ }
254
256
if ( state . replaceStarted ) {
255
257
replaceAll ( cm , query , withText ) ;
256
258
state . replaceStarted = false ;
@@ -491,104 +493,105 @@ function replaceAll(cm, query, text) {
491
493
var getQueryDialog = function ( ) {
492
494
return ( `
493
495
<div class="CodeMirror-find-popup-container">
494
- <div class="Toggle-replace-btn-div">
496
+ <div id="Btn-Toggle-replace-div" class="Toggle-replace-btn-div">
495
497
<button
496
- title="${ i18n . t ( 'CodemirrorFindAndReplace.Replace ' ) } "
497
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Replace ' ) } "
498
- role="button"
498
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.ToggleReplace ' ) } "
499
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.ToggleReplace ' ) } "
500
+ role="button" id="Btn-Toggle-replace"
499
501
class="CodeMirror-search-modifier-button CodeMirror-replace-toggle-button"
500
502
>
501
503
<span aria-hidden="true" class="button">
502
504
${ triangleArrowRight }
503
505
</span>
504
506
</button>
505
507
</div>
506
- <div class="CodeMirror-find-input-fields">
507
- <div class="CodeMirror-find-div">
508
- <div class="CodeMirror-find-input">
509
- <input id="Find-input-field" type="text" class="search-input CodeMirror-search-field" placeholder="${ i18n . t ( 'CodemirrorFindAndReplace.FindPlaceholder' ) } " />
510
- </div>
511
- <div class="CodeMirror-find-controls">
512
- <div class="CodeMirror-search-modifiers button-wrap">
513
- <button
514
- title="${ i18n . t ( 'CodemirrorFindAndReplace.Regex' ) } "
515
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Regex' ) } "
516
- role="checkbox"
517
- class="CodeMirror-search-modifier-button CodeMirror-regexp-button"
518
- >
519
- <span aria-hidden="true" class="button">.*</span>
520
- </button>
521
- <button
522
- title="${ i18n . t ( 'CodemirrorFindAndReplace.CaseSensitive' ) } "
523
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.CaseSensitive' ) } "
524
- role="checkbox"
525
- class="CodeMirror-search-modifier-button CodeMirror-case-button"
526
- >
527
- <span aria-hidden="true" class="button">Aa</span>
528
- </button>
529
- <button
530
- title="${ i18n . t ( 'CodemirrorFindAndReplace.WholeWords' ) } "
531
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.WholeWords' ) } "
532
- role="checkbox"
533
- class="CodeMirror-search-modifier-button CodeMirror-word-button"
534
- >
535
- <span aria-hidden="true" class="button">" "</span>
536
- </button>
537
- </div>
538
- <div class="CodeMirror-search-nav">
539
- <p class="CodeMirror-search-results">${ i18n . t ( 'CodemirrorFindAndReplace.NoResults' ) } </p>
540
- <button
541
- title="${ i18n . t ( 'CodemirrorFindAndReplace.Previous' ) } "
542
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Previous' ) } "
543
- class="CodeMirror-search-button icon up-arrow prev"
544
- >
545
- <span aria-hidden="true">
546
- ${ upArrow }
547
- </span>
548
- </button>
549
- <button
550
- title="${ i18n . t ( 'CodemirrorFindAndReplace.Next' ) } "
551
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Next' ) } "
552
- class="CodeMirror-search-button icon down-arrow next"
553
- >
554
- <span aria-hidden="true">
555
- ${ downArrow }
556
- </span>
557
- </button>
558
- </div>
559
- <div class="CodeMirror-close-button-container">
560
- <button
561
- title="${ i18n . t ( 'CodemirrorFindAndReplace.Close' ) } "
562
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Close' ) } "
563
- class="CodeMirror-close-button close icon"
564
- >
565
- <span aria-hidden="true">
566
- ${ exitIcon }
567
- </span>
568
- </button>
569
- </div>
570
- </div>
508
+ <div class="CodeMirror-search-inputs">
509
+ <div class="CodeMirror-find-input">
510
+ <input id="Find-input-field" type="text" class="search-input CodeMirror-search-field" placeholder="${ i18n . t ( 'CodemirrorFindAndReplace.FindPlaceholder' ) } " />
571
511
</div>
572
- <div style="height: 0px; overflow: hidden;" class="CodeMirror-replace-div">
512
+ <div style="display: none;" id="Replace-input-div"
513
+ class="CodeMirror-replace-input">
573
514
<input id="Replace-input-field" type="text" placeholder="${ i18n . t ( 'CodemirrorFindAndReplace.ReplacePlaceholder' ) } " class="search-input CodeMirror-search-field"/>
574
- <div class="CodeMirror-replace-controls">
515
+ </div>
516
+ </div>
517
+ <div class="CodeMirror-search-controls">
518
+ <div style="display: none;" id="Replace-controls-div" class="CodeMirror-replace-controls">
519
+ <button
520
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.Replace' ) } "
521
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Replace' ) } "
522
+ role="button"
523
+ id="Btn-replace"
524
+ class="CodeMirror-search-modifier-button CodeMirror-replace-button"
525
+ >
526
+ ${ i18n . t ( 'CodemirrorFindAndReplace.Replace' ) }
527
+ </button>
528
+ <button
529
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.ReplaceAll' ) } "
530
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.ReplaceAll' ) } "
531
+ role="button"
532
+ id="Btn-replace-all"
533
+ class="CodeMirror-search-modifier-button CodeMirror-replace-button"
534
+ >
535
+ ${ i18n . t ( 'CodemirrorFindAndReplace.ReplaceAll' ) }
536
+ </button>
537
+ </div>
538
+ <div class="CodeMirror-find-controls">
539
+ <div class="CodeMirror-search-modifiers button-wrap">
575
540
<button
576
- title="${ i18n . t ( 'CodemirrorFindAndReplace.Replace' ) } "
577
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Replace' ) } "
578
- role="button"
579
- id="Btn-replace"
580
- class="CodeMirror-search-modifier-button CodeMirror-replace-button"
541
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.Regex' ) } "
542
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Regex' ) } "
543
+ role="checkbox"
544
+ class="CodeMirror-search-modifier-button CodeMirror-regexp-button"
581
545
>
582
- ${ i18n . t ( 'CodemirrorFindAndReplace.Replace' ) }
546
+ <span aria-hidden="true" class="button">.*</span>
583
547
</button>
584
548
<button
585
- title="${ i18n . t ( 'CodemirrorFindAndReplace.ReplaceAll' ) } "
586
- aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.ReplaceAll' ) } "
587
- role="button"
588
- id="Btn-replace-all"
589
- class="CodeMirror-search-modifier-button CodeMirror-replace-button"
549
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.CaseSensitive' ) } "
550
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.CaseSensitive' ) } "
551
+ role="checkbox"
552
+ class="CodeMirror-search-modifier-button CodeMirror-case-button"
553
+ >
554
+ <span aria-hidden="true" class="button">Aa</span>
555
+ </button>
556
+ <button
557
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.WholeWords' ) } "
558
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.WholeWords' ) } "
559
+ role="checkbox"
560
+ class="CodeMirror-search-modifier-button CodeMirror-word-button"
561
+ >
562
+ <span aria-hidden="true" class="button">" "</span>
563
+ </button>
564
+ </div>
565
+ <div class="CodeMirror-search-nav">
566
+ <p class="CodeMirror-search-results">${ i18n . t ( 'CodemirrorFindAndReplace.NoResults' ) } </p>
567
+ <button
568
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.Previous' ) } "
569
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Previous' ) } "
570
+ class="CodeMirror-search-button icon up-arrow prev"
571
+ >
572
+ <span aria-hidden="true">
573
+ ${ upArrow }
574
+ </span>
575
+ </button>
576
+ <button
577
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.Next' ) } "
578
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Next' ) } "
579
+ class="CodeMirror-search-button icon down-arrow next"
580
+ >
581
+ <span aria-hidden="true">
582
+ ${ downArrow }
583
+ </span>
584
+ </button>
585
+ </div>
586
+ <div class="CodeMirror-close-button-container">
587
+ <button
588
+ title="${ i18n . t ( 'CodemirrorFindAndReplace.Close' ) } "
589
+ aria-label="${ i18n . t ( 'CodemirrorFindAndReplace.Close' ) } "
590
+ class="CodeMirror-close-button close icon"
590
591
>
591
- ${ i18n . t ( 'CodemirrorFindAndReplace.ReplaceAll' ) }
592
+ <span aria-hidden="true">
593
+ ${ exitIcon }
594
+ </span>
592
595
</button>
593
596
</div>
594
597
</div>
0 commit comments