mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 03:46:37 +01:00
autocomplete for add link dialog, #203
This commit is contained in:
@@ -15,7 +15,6 @@ const $prefixFormGroup = $("#add-link-prefix-form-group");
|
||||
const $linkTypeDiv = $("#add-link-type-div");
|
||||
const $linkTypes = $("input[name='add-link-type']");
|
||||
const $linkTypeHtml = $linkTypes.filter('input[value="html"]');
|
||||
const $showRecentNotesButton = $dialog.find(".show-recent-notes-button");
|
||||
|
||||
function setLinkType(linkType) {
|
||||
$linkTypes.each(function () {
|
||||
@@ -51,50 +50,31 @@ async function showDialog() {
|
||||
$linkTitle.val(noteTitle);
|
||||
}
|
||||
|
||||
await $autoComplete.autocomplete({
|
||||
source: noteAutocompleteService.autocompleteSource,
|
||||
minLength: 0,
|
||||
change: async (event, ui) => {
|
||||
if (!ui.item) {
|
||||
return;
|
||||
}
|
||||
noteAutocompleteService.initNoteAutocomplete($autoComplete);
|
||||
|
||||
const notePath = linkService.getNotePathFromLabel(ui.item.value);
|
||||
$autoComplete.on('autocomplete:selected', function(event, suggestion, dataset) {
|
||||
if (!suggestion.path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!notePath) {
|
||||
return;
|
||||
}
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(suggestion.path);
|
||||
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||
|
||||
if (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
|
||||
// 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) => {
|
||||
const notePath = linkService.getNotePathFromLabel(ui.item.value);
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||
|
||||
await setDefaultLinkTitle(noteId);
|
||||
|
||||
event.preventDefault();
|
||||
if (noteId) {
|
||||
setDefaultLinkTitle(noteId);
|
||||
}
|
||||
});
|
||||
|
||||
showRecentNotes();
|
||||
$autoComplete.on('autocomplete:cursorchanged', function(event, suggestion, dataset) {
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(suggestion.path);
|
||||
|
||||
setDefaultLinkTitle(noteId);
|
||||
});
|
||||
|
||||
noteAutocompleteService.showRecentNotes($autoComplete);
|
||||
}
|
||||
|
||||
$form.submit(() => {
|
||||
const value = $autoComplete.val();
|
||||
|
||||
const notePath = linkService.getNotePathFromLabel(value);
|
||||
const notePath = $autoComplete.getSelectedPath();
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||
|
||||
if (notePath) {
|
||||
@@ -131,6 +111,9 @@ $form.submit(() => {
|
||||
$dialog.modal('hide');
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.error("No path to add link.");
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
@@ -152,14 +135,8 @@ function linkTypeChanged() {
|
||||
$linkTypeDiv.toggle(!hasSelection());
|
||||
}
|
||||
|
||||
function showRecentNotes() {
|
||||
$autoComplete.autocomplete("search", "");
|
||||
}
|
||||
|
||||
$linkTypes.change(linkTypeChanged);
|
||||
|
||||
$showRecentNotesButton.click(showRecentNotes);
|
||||
|
||||
export default {
|
||||
showDialog
|
||||
};
|
||||
@@ -5,7 +5,6 @@ import noteAutocompleteService from '../services/note_autocomplete.js';
|
||||
const $dialog = $("#jump-to-note-dialog");
|
||||
const $autoComplete = $("#jump-to-note-autocomplete");
|
||||
const $showInFullTextButton = $("#show-in-full-text-button");
|
||||
const $showRecentNotesButton = $dialog.find(".show-recent-notes-button");
|
||||
|
||||
$dialog.on("shown.bs.modal", e => $autoComplete.focus());
|
||||
|
||||
@@ -45,11 +44,8 @@ function showInFullText(e) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
$showInFullTextButton.click(showInFullText);
|
||||
|
||||
$showRecentNotesButton.click(noteAutocompleteService.showRecentNotes);
|
||||
|
||||
$dialog.bind('keydown', 'ctrl+return', showInFullText);
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user