trilium/src/public/javascripts/dialogs/jump_to_note.js

97 lines
2.6 KiB
JavaScript
Raw Normal View History

import treeService from '../services/tree.js';
2018-06-06 11:28:10 +08:00
import searchNotesService from '../services/search_notes.js';
import noteautocompleteService from '../services/note_autocomplete.js';
import linkService from "../services/link.js";
const $dialog = $("#jump-to-note-dialog");
const $autoComplete = $("#jump-to-note-autocomplete");
2018-06-06 11:28:10 +08:00
const $showInFullTextButton = $("#show-in-full-text-button");
const $showRecentNotesButton = $dialog.find(".show-recent-notes-button");
$dialog.on("shown.bs.modal", e => $autoComplete.focus());
async function showDialog() {
glob.activeDialog = $dialog;
2017-11-20 11:31:30 +08:00
$autoComplete.val('');
$dialog.modal();
$autoComplete.autocomplete({
appendTo: document.querySelector('body'),
hint: false,
autoselect: true,
openOnFocus: true
}, [
{
source: noteautocompleteService.autocompleteSource,
displayKey: 'label',
templates: {
suggestion: function(suggestion) {
return suggestion.label;
}
}
}
]).on('autocomplete:selected', function(event, suggestion, dataset) {
console.log("selected: ", event, suggestion, dataset);
return;
if (ui.item.value === 'No results') {
return false;
}
const notePath = linkService.getNotePathFromLabel(ui.item.value);
treeService.activateNote(notePath);
$dialog.modal('hide');
});
// await $autoComplete.autocomplete({
// source: noteautocompleteService.autocompleteSource,
// focus: event => event.preventDefault(),
// minLength: 0,
// autoFocus: true,
// select: function (event, ui) {
// if (ui.item.value === 'No results') {
// return false;
// }
//
// const notePath = linkService.getNotePathFromLabel(ui.item.value);
//
// treeService.activateNote(notePath);
//
// $dialog.modal('hide');
// }
// });
//showRecentNotes();
}
2017-11-20 09:36:13 +08:00
2018-06-06 11:28:10 +08:00
function showInFullText(e) {
// stop from propagating upwards (dangerous especially with ctrl+enter executable javascript notes)
e.preventDefault();
e.stopPropagation();
const searchText = $autoComplete.val();
searchNotesService.resetSearch();
searchNotesService.showSearch();
searchNotesService.doSearch(searchText);
$dialog.modal('hide');
2018-06-06 11:28:10 +08:00
}
function showRecentNotes() {
$autoComplete.autocomplete("search", "");
}
2018-06-06 11:28:10 +08:00
$showInFullTextButton.click(showInFullText);
$showRecentNotesButton.click(showRecentNotes);
2018-06-06 11:28:10 +08:00
$dialog.bind('keydown', 'ctrl+return', showInFullText);
export default {
showDialog
};