fix autofilling autocomplete label on focus

This commit is contained in:
azivner 2017-09-03 19:15:50 -04:00
parent 4adf4fcc4a
commit 1c5483905d

View File

@ -130,12 +130,12 @@ $(document).bind('keydown', 'alt+l', function() {
});
}
function setDefaultLinkTitle() {
const val = $("#noteAutocomplete").val();
const noteId = getNodeIdFromLabel(val);
if (noteId) {
function setDefaultLinkTitle(noteId) {
const note = getNodeByKey(noteId);
if (!note) {
return;
}
let noteTitle = note.title;
if (noteTitle.endsWith(" (clone)")) {
@ -144,13 +144,25 @@ $(document).bind('keydown', 'alt+l', function() {
$("#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);
}
});
});