Add matches search into code mirror

This commit is contained in:
davidbmx 2019-09-10 12:00:27 -05:00
parent 876f0b30fc
commit 22f958e50a

View file

@ -73,7 +73,7 @@ export default function(CodeMirror) {
CodeMirror.on(searchField, "keyup", function (e) {
if (e.keyCode !== 13 && searchField.value.length > 1) { // not enter and more than 1 character to search
startSearch(cm, getSearchState(cm), searchField.value);
} else {
} else if (searchField.value.length <= 1) {
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = '';
}
});
@ -295,10 +295,9 @@ export default function(CodeMirror) {
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
state.annotate = cm.showMatchesOnScrollbar(state.query, state.caseInsensitive);
}
var num_match = cm.state.search.annotate.matches.length;
var text_match =
'Results: ' + num_match;
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = text_match;
if (originalQuery) {
return findNext(cm, false);
}
}
function doSearch(cm, rev, persistent, immediate, ignoreQuery) {
@ -362,6 +361,11 @@ export default function(CodeMirror) {
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 60);
state.posFrom = cursor.from(); state.posTo = cursor.to();
var num_match = cm.state.search.annotate.matches.length;
var next = cm.state.search.annotate.matches
.findIndex(s => s.from.ch === cursor.from().ch && s.from.line === cursor.from().line) + 1;
var text_match = next + '/' + num_match;
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = text_match;
if (callback) callback(cursor.from(), cursor.to())
});}