improvements to search, fixing issue #1

This commit is contained in:
azivner
2018-01-15 20:54:22 -05:00
parent 31a69a96c0
commit 7ea23586fe
3 changed files with 27 additions and 19 deletions

View File

@@ -30,7 +30,7 @@ const searchTree = (function() {
return treeEl.fancytree('getTree');
}
searchInputEl.keyup(e => {
searchInputEl.keyup(async e => {
const searchText = searchInputEl.val();
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") {
@@ -39,12 +39,14 @@ const searchTree = (function() {
}
if (e && e.which === $.ui.keyCode.ENTER) {
server.get('notes?search=' + searchText).then(resp => {
// Pass a string to perform case insensitive matching
getTree().filterBranches(node => {
return resp.includes(node.data.note_id);
});
});
const noteIds = await server.get('notes?search=' + encodeURIComponent(searchText));
for (const noteId of noteIds) {
await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true});
}
// Pass a string to perform case insensitive matching
getTree().filterBranches(node => noteIds.includes(node.data.note_id));
}
}).focus();