Merge pull request #1151 from davidbmx/master
Add matches search into code mirror fixes #936
This commit is contained in:
commit
8d0e59efc2
1 changed files with 15 additions and 1 deletions
|
@ -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 if (searchField.value.length <= 1) {
|
||||||
|
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,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);
|
||||||
}
|
}
|
||||||
|
if (originalQuery) {
|
||||||
|
return findNext(cm, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSearch(cm, rev, persistent, immediate, ignoreQuery) {
|
function doSearch(cm, rev, persistent, immediate, ignoreQuery) {
|
||||||
|
@ -350,11 +356,19 @@ export default function(CodeMirror) {
|
||||||
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
|
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
|
||||||
if (!cursor.find(rev)) {
|
if (!cursor.find(rev)) {
|
||||||
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
|
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
|
||||||
if (!cursor.find(rev)) return;
|
if (!cursor.find(rev)) {
|
||||||
|
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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