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
fix autofilling autocomplete label on focus
azivner1c5483905df8
diff --git a/static/js/init.js b/static/js/init.jsindex 51d93842a6..b31004c23b 100644--- a/static/js/init.js+++ b/static/js/init.js@@ -130,27 +130,39 @@ $(document).bind('keydown', 'alt+l', function() {});}- function setDefaultLinkTitle() {- const val = $("#noteAutocomplete").val();- const noteId = getNodeIdFromLabel(val);+ function setDefaultLinkTitle(noteId) {+ const note = getNodeByKey(noteId);+ if (!note) {+ return;+ }- if (noteId) {- const note = getNodeByKey(noteId);- let noteTitle = note.title;+ let noteTitle = note.title;- if (noteTitle.endsWith(" (clone)")) {- noteTitle = noteTitle.substr(0, noteTitle.length - 8);- }-- $("#linkTitle").val(noteTitle);+ if (noteTitle.endsWith(" (clone)")) {+ noteTitle = noteTitle.substr(0, noteTitle.length - 8);}++ $("#linkTitle").val(noteTitle);}$("#noteAutocomplete").autocomplete({source: autocompleteItems,minLength: 0,- change: setDefaultLinkTitle,- focus: setDefaultLinkTitle+ change: function () {+ const val = $("#noteAutocomplete").val();+ const noteId = getNodeIdFromLabel(val);++ if (noteId) {+ setDefaultLinkTitle(noteId);+ }+ },+ // this is called when user goes through autocomplete list with keyboard+ // at this point the item isn't selected yet so we use supplied ui.item to see where the cursor is+ focus: function (event, ui) {+ const noteId = getNodeIdFromLabel(ui.item.value);++ setDefaultLinkTitle(noteId);+ }});});