mirror of
https://github.com/zadam/trilium.git
synced 2024-11-11 09:46:25 +08:00
#129, add link autocomplete now displays recent notes as well
This commit is contained in:
parent
2a08aef885
commit
f578e001b0
1 changed files with 20 additions and 6 deletions
|
@ -53,12 +53,17 @@ async function showDialog() {
|
||||||
$linkTitle.val(noteTitle);
|
$linkTitle.val(noteTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
$autoComplete.autocomplete({
|
await $autoComplete.autocomplete({
|
||||||
source: async function(request, response) {
|
source: async function(request, response) {
|
||||||
const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
|
const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
|
||||||
|
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
response(result);
|
response(result.map(row => {
|
||||||
|
return {
|
||||||
|
label: row.label,
|
||||||
|
value: row.label + ' (' + row.value + ')'
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
response([{
|
response([{
|
||||||
|
@ -67,10 +72,10 @@ async function showDialog() {
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
minLength: 2,
|
minLength: 0,
|
||||||
change: async () => {
|
change: async (event, ui) => {
|
||||||
const val = $autoComplete.val();
|
const notePath = linkService.getNodePathFromLabel(ui.item.value);
|
||||||
const notePath = linkService.getNodePathFromLabel(val);
|
|
||||||
if (!notePath) {
|
if (!notePath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +86,11 @@ async function showDialog() {
|
||||||
await setDefaultLinkTitle(noteId);
|
await setDefaultLinkTitle(noteId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
select: function (event, ui) {
|
||||||
|
if (ui.item.value === 'No results') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
// this is called when user goes through autocomplete list with keyboard
|
// 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
|
// at this point the item isn't selected yet so we use supplied ui.item to see WHERE the cursor is
|
||||||
focus: async (event, ui) => {
|
focus: async (event, ui) => {
|
||||||
|
@ -88,8 +98,12 @@ async function showDialog() {
|
||||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||||
|
|
||||||
await setDefaultLinkTitle(noteId);
|
await setDefaultLinkTitle(noteId);
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$autoComplete.autocomplete("search", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
$form.submit(() => {
|
$form.submit(() => {
|
||||||
|
|
Loading…
Reference in a new issue