Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixed autocomplete
azivner658f4872af4a
diff --git a/public/javascripts/dialogs/add_link.js b/public/javascripts/dialogs/add_link.jsindex 23a178b285..02f3c43c21 100644--- a/public/javascripts/dialogs/add_link.js+++ b/public/javascripts/dialogs/add_link.js@@ -27,7 +27,7 @@ const addLink = (function() {}autoCompleteEl.autocomplete({- source: getAutocompleteItems(glob.allNoteIds),+ source: noteTree.getAutocompleteItems(),minLength: 0,change: () => {const val = autoCompleteEl.val();diff --git a/public/javascripts/dialogs/jump_to_note.js b/public/javascripts/dialogs/jump_to_note.jsindex dac1f38039..8051fd8d24 100644--- a/public/javascripts/dialogs/jump_to_note.js+++ b/public/javascripts/dialogs/jump_to_note.js@@ -16,7 +16,7 @@ const jumpToNote = (function() {});autoCompleteEl.autocomplete({- source: getAutocompleteItems(glob.allNoteIds),+ source: noteTree.getAutocompleteItems(),minLength: 0});}diff --git a/public/javascripts/init.js b/public/javascripts/init.jsindex 66efd2e79f..c96fea726f 100644--- a/public/javascripts/init.js+++ b/public/javascripts/init.js@@ -57,10 +57,10 @@ $.ui.autocomplete.filter = (array, terms) => {for (const item of array) {let found = true;- const lcValue = item.value.toLowerCase();+ const lcLabel = item.label.toLowerCase();for (const token of tokens) {- if (lcValue.indexOf(token) === -1) {+ if (lcLabel.indexOf(token) === -1) {found = false;break;}diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.jsindex 7dc9e101ba..05bf3b3253 100644--- a/public/javascripts/note_tree.js+++ b/public/javascripts/note_tree.js@@ -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};})();\ No newline at end of filediff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.jsindex 2b0a0c4adb..916b950442 100644--- a/public/javascripts/tree_utils.js+++ b/public/javascripts/tree_utils.js@@ -35,7 +35,7 @@ const treeUtils = (function() {}function getFullName(noteTreeId) {- let note = noteTree.getByNoteId(noteTreeId);+ let note = noteTree.getByNoteTreeId(noteTreeId);if (note === null) {return "[unknown]";@@ -46,7 +46,7 @@ const treeUtils = (function() {while (note) {path.push(note.note_title);- note = noteTree.getByNoteId(note.note_pid);+ note = noteTree.getByNoteTreeId(note.note_pid);}return path.reverse().join(" > ");diff --git a/public/javascripts/utils.js b/public/javascripts/utils.jsindex a1178c8064..ebd9463dde 100644--- a/public/javascripts/utils.js+++ b/public/javascripts/utils.js@@ -20,25 +20,6 @@ function showError(str) {error.fadeOut(10000);}-function getAutocompleteItems(noteIds) {- const autocompleteItems = [];-- for (const noteId of noteIds) {- const fullName = treeUtils.getFullName(noteId);-- if (fullName !== null) {- autocompleteItems.push({- value: fullName + " (" + noteId + ")",- label: fullName- });- }- }-- autocompleteItems.sort((a, b) => a.value < b.value ? -1 : 1);-- return autocompleteItems;-}-function getDateFromTS(timestamp) {// Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling// see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript