fixed autocomplete

This commit is contained in:
azivner
2017-11-19 19:39:39 -05:00
parent e992087720
commit 658f4872af
6 changed files with 49 additions and 29 deletions

View File

@@ -418,8 +418,8 @@ const noteTree = (function() {
tree.clearFilter();
}
function getByNoteId(noteId) {
return notesMap[noteId];
function getByNoteTreeId(noteTreeId) {
return notesMap[noteTreeId];
}
// note that if you want to access data like note_id or is_protected, you need to go into "data" property
@@ -444,6 +444,44 @@ const noteTree = (function() {
node.toggleClass("protected", !!node.data.is_protected);
}
function getAutocompleteItems(parentNoteId, notePath, titlePath) {
if (!parentNoteId) {
parentNoteId = 'root';
}
if (!parentToChildren[parentNoteId]) {
return [];
}
if (!notePath) {
notePath = '';
}
if (!titlePath) {
titlePath = '';
}
const autocompleteItems = [];
for (const childNoteId of parentToChildren[parentNoteId]) {
const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId;
const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId);
autocompleteItems.push({
value: childNotePath,
label: childTitlePath
});
const childItems = getAutocompleteItems(childNoteId, childNotePath, childTitlePath);
for (const childItem of childItems) {
autocompleteItems.push(childItem);
}
}
return autocompleteItems;
}
$("button#reset-search-button").click(resetSearch);
$("input[name=search]").keyup(e => {
@@ -477,7 +515,7 @@ const noteTree = (function() {
collapseTree,
scrollToCurrentNote,
toggleSearch,
getByNoteId,
getByNoteTreeId,
getKeyFromNoteTreeId,
getNoteTreeIdFromKey,
setCurrentNoteTreeBasedOnProtectedStatus,
@@ -486,6 +524,7 @@ const noteTree = (function() {
activateNode,
getCurrentNotePath,
getNoteTitle,
setCurrentNotePathToHash
setCurrentNotePathToHash,
getAutocompleteItems
};
})();