trilium/public/javascripts/dialogs/jump_to_note.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 01:59:43 +08:00
const jumpToNote = (function() {
const dialogEl = $("#jump-to-note-dialog");
const autoCompleteEl = $("#jump-to-note-autocomplete");
const formEl = $("#jump-to-note-form");
2017-11-20 09:36:13 +08:00
async function showDialog() {
2017-11-05 05:03:15 +08:00
glob.activeDialog = dialogEl;
2017-11-05 01:59:43 +08:00
autoCompleteEl.val('');
2017-11-05 01:59:43 +08:00
dialogEl.dialog({
modal: true,
width: 800
});
2017-10-11 08:37:45 +08:00
2017-11-20 09:36:13 +08:00
await autoCompleteEl.autocomplete({
source: await stopWatch("building autocomplete", noteTree.getAutocompleteItems),
2017-11-05 01:59:43 +08:00
minLength: 0
});
}
2017-11-20 11:31:30 +08:00
function getSelectedNotePath() {
2017-11-05 01:59:43 +08:00
const val = autoCompleteEl.val();
2017-11-20 11:31:30 +08:00
return link.getNodePathFromLabel(val);
}
function goToNote() {
const notePath = getSelectedNotePath();
2017-11-20 09:36:13 +08:00
if (notePath) {
noteTree.activateNode(notePath);
2017-11-05 01:59:43 +08:00
dialogEl.dialog('close');
}
2017-11-20 09:36:13 +08:00
}
2017-12-19 12:41:13 +08:00
$(document).bind('keydown', 'ctrl+j', e => {
showDialog();
e.preventDefault();
});
2017-11-20 09:36:13 +08:00
formEl.submit(() => {
const action = dialogEl.find("button:focus").val();
goToNote();
2017-11-05 01:59:43 +08:00
return false;
});
2017-11-05 01:59:43 +08:00
return {
showDialog
};
})();