Add matches search into code mirror

This commit is contained in:
David 2019-09-02 08:02:49 -05:00
parent aa318e0d2d
commit 876f0b30fc

View file

@ -73,6 +73,8 @@ 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 {
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = '';
} }
}); });
@ -260,6 +262,7 @@ export default function(CodeMirror) {
</button> </button>
</div> </div>
<div class="CodeMirror-search-nav"> <div class="CodeMirror-search-nav">
<button class="CodeMirror-search-results"></button>
<button <button
title="Previous" title="Previous"
aria-label="Previous" aria-label="Previous"
@ -292,6 +295,10 @@ 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;
var text_match =
'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) {