@@ -186,16 +186,6 @@ function persistentDialog(cm, text, deflt, onEnter, onKeyDown) {
186186
187187 var replaceField = document . getElementById ( 'Replace-input-field' ) ;
188188 CodeMirror . on ( replaceField , "keyup" , function ( e ) {
189- // if (e.keyCode === 13) {
190- // // If enter is pressed, then shift focus to replace field
191- // var state = getSearchState(cm);
192- // startSearch(cm, state, searchField.value);
193- // state.replaceStarted = true;
194- // cm.focus();
195- // CodeMirror.commands.findNext(cm);
196- // searchField.blur();
197- // replaceField.focus();
198- // }
199189 if ( ! searchField . value ) {
200190 searchField . focus ( ) ;
201191 return ;
@@ -206,7 +196,12 @@ function persistentDialog(cm, text, deflt, onEnter, onKeyDown) {
206196 if ( e . keyCode === 13 ) // if enter
207197 {
208198 var cursor = getSearchCursor ( cm , query , cm . getCursor ( "from" ) ) ;
199+ var start = cursor . from ( ) ;
209200 var match = cursor . findNext ( ) ;
201+ if ( ! match ) {
202+ cursor = getSearchCursor ( cm , query ) ;
203+ if ( ! ( match = cursor . findNext ( ) ) || ( start && cursor . from ( ) . line == start . line && cursor . from ( ) . ch == start . ch ) ) return ;
204+ }
210205 cm . setSelection ( cursor . from ( ) , cursor . to ( ) ) ;
211206 state . replaceStarted = true ;
212207 doReplace ( match , cursor , query , withText ) ;
@@ -217,9 +212,9 @@ function persistentDialog(cm, text, deflt, onEnter, onKeyDown) {
217212 cursor . replace ( typeof query == "string" ? withText :
218213 withText . replace ( / \$ ( \d ) / g, function ( _ , i ) { return match [ i ] ; } ) ) ;
219214 cursor . findNext ( ) ;
220- cm . focus ( ) ;
215+ // cm.focus();
221216 CodeMirror . commands . findNext ( cm ) ;
222- searchField . blur ( ) ;
217+ // searchField.blur();
223218 } ;
224219
225220 var doReplaceButton = document . getElementById ( 'Btn-replace' ) ;
0 commit comments