@@ -73,6 +73,8 @@ export default function(CodeMirror) {
73
73
CodeMirror . on ( searchField , "keyup" , function ( e ) {
74
74
if ( e . keyCode !== 13 && searchField . value . length > 1 ) { // not enter and more than 1 character to search
75
75
startSearch ( cm , getSearchState ( cm ) , searchField . value ) ;
76
+ } else if ( searchField . value . length <= 1 ) {
77
+ cm . display . wrapper . querySelector ( '.CodeMirror-search-results' ) . innerText = '' ;
76
78
}
77
79
} ) ;
78
80
@@ -260,6 +262,7 @@ export default function(CodeMirror) {
260
262
</button>
261
263
</div>
262
264
<div class="CodeMirror-search-nav">
265
+ <button class="CodeMirror-search-results"></button>
263
266
<button
264
267
title="Previous"
265
268
aria-label="Previous"
@@ -292,6 +295,9 @@ export default function(CodeMirror) {
292
295
if ( state . annotate ) { state . annotate . clear ( ) ; state . annotate = null ; }
293
296
state . annotate = cm . showMatchesOnScrollbar ( state . query , state . caseInsensitive ) ;
294
297
}
298
+ if ( originalQuery ) {
299
+ return findNext ( cm , false ) ;
300
+ }
295
301
}
296
302
297
303
function doSearch ( cm , rev , persistent , immediate , ignoreQuery ) {
@@ -350,11 +356,19 @@ export default function(CodeMirror) {
350
356
var cursor = getSearchCursor ( cm , state . query , rev ? state . posFrom : state . posTo ) ;
351
357
if ( ! cursor . find ( rev ) ) {
352
358
cursor = getSearchCursor ( cm , state . query , rev ? CodeMirror . Pos ( cm . lastLine ( ) ) : CodeMirror . Pos ( cm . firstLine ( ) , 0 ) ) ;
353
- if ( ! cursor . find ( rev ) ) return ;
359
+ if ( ! cursor . find ( rev ) ) {
360
+ cm . display . wrapper . querySelector ( '.CodeMirror-search-results' ) . innerText = '' ;
361
+ return ;
362
+ }
354
363
}
355
364
cm . setSelection ( cursor . from ( ) , cursor . to ( ) ) ;
356
365
cm . scrollIntoView ( { from : cursor . from ( ) , to : cursor . to ( ) } , 60 ) ;
357
366
state . posFrom = cursor . from ( ) ; state . posTo = cursor . to ( ) ;
367
+ var num_match = cm . state . search . annotate . matches . length ;
368
+ var next = cm . state . search . annotate . matches
369
+ . findIndex ( s => s . from . ch === cursor . from ( ) . ch && s . from . line === cursor . from ( ) . line ) + 1 ;
370
+ var text_match = next + '/' + num_match ;
371
+ cm . display . wrapper . querySelector ( '.CodeMirror-search-results' ) . innerText = text_match ;
358
372
if ( callback ) callback ( cursor . from ( ) , cursor . to ( ) )
359
373
} ) ; }
360
374
0 commit comments