Add matches search into code mirror
This commit is contained in:
parent
876f0b30fc
commit
22f958e50a
1 changed files with 9 additions and 5 deletions
|
@ -73,7 +73,7 @@ export default function(CodeMirror) {
|
||||||
CodeMirror.on(searchField, "keyup", function (e) {
|
CodeMirror.on(searchField, "keyup", function (e) {
|
||||||
if (e.keyCode !== 13 && searchField.value.length > 1) { // not enter and more than 1 character to search
|
if (e.keyCode !== 13 && searchField.value.length > 1) { // not enter and more than 1 character to search
|
||||||
startSearch(cm, getSearchState(cm), searchField.value);
|
startSearch(cm, getSearchState(cm), searchField.value);
|
||||||
} else {
|
} else if (searchField.value.length <= 1) {
|
||||||
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = '';
|
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; }
|
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
|
||||||
state.annotate = cm.showMatchesOnScrollbar(state.query, state.caseInsensitive);
|
state.annotate = cm.showMatchesOnScrollbar(state.query, state.caseInsensitive);
|
||||||
}
|
}
|
||||||
var num_match = cm.state.search.annotate.matches.length;
|
if (originalQuery) {
|
||||||
var text_match =
|
return findNext(cm, false);
|
||||||
'Results: ' + num_match;
|
}
|
||||||
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = text_match;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSearch(cm, rev, persistent, immediate, ignoreQuery) {
|
function doSearch(cm, rev, persistent, immediate, ignoreQuery) {
|
||||||
|
@ -362,6 +361,11 @@ export default function(CodeMirror) {
|
||||||
cm.setSelection(cursor.from(), cursor.to());
|
cm.setSelection(cursor.from(), cursor.to());
|
||||||
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 60);
|
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 60);
|
||||||
state.posFrom = cursor.from(); state.posTo = cursor.to();
|
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())
|
if (callback) callback(cursor.from(), cursor.to())
|
||||||
});}
|
});}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue