Skip to content

Commit 22f958e

Browse files
committed
Add matches search into code mirror
1 parent 876f0b3 commit 22f958e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

client/utils/codemirror-search.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function(CodeMirror) {
7373
CodeMirror.on(searchField, "keyup", function (e) {
7474
if (e.keyCode !== 13 && searchField.value.length > 1) { // not enter and more than 1 character to search
7575
startSearch(cm, getSearchState(cm), searchField.value);
76-
} else {
76+
} else if (searchField.value.length <= 1) {
7777
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = '';
7878
}
7979
});
@@ -295,10 +295,9 @@ export default function(CodeMirror) {
295295
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
296296
state.annotate = cm.showMatchesOnScrollbar(state.query, state.caseInsensitive);
297297
}
298-
var num_match = cm.state.search.annotate.matches.length;
299-
var text_match =
300-
'Results: ' + num_match;
301-
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = text_match;
298+
if (originalQuery) {
299+
return findNext(cm, false);
300+
}
302301
}
303302

304303
function doSearch(cm, rev, persistent, immediate, ignoreQuery) {
@@ -362,6 +361,11 @@ export default function(CodeMirror) {
362361
cm.setSelection(cursor.from(), cursor.to());
363362
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 60);
364363
state.posFrom = cursor.from(); state.posTo = cursor.to();
364+
var num_match = cm.state.search.annotate.matches.length;
365+
var next = cm.state.search.annotate.matches
366+
.findIndex(s => s.from.ch === cursor.from().ch && s.from.line === cursor.from().line) + 1;
367+
var text_match = next + '/' + num_match;
368+
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = text_match;
365369
if (callback) callback(cursor.from(), cursor.to())
366370
});}
367371

0 commit comments

Comments
 (0)