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

61 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
import treeService from '../note_tree.js';
import link from '../link.js';
import utils from '../utils.js';
const $showDialogButton = $("#jump-to-note-button");
const $dialog = $("#jump-to-note-dialog");
const $autoComplete = $("#jump-to-note-autocomplete");
const $form = $("#jump-to-note-form");
async function showDialog() {
glob.activeDialog = $dialog;
2017-11-20 11:31:30 +08:00
$autoComplete.val('');
$dialog.dialog({
modal: true,
width: 800
});
await $autoComplete.autocomplete({
source: await utils.stopWatch("building autocomplete", treeService.getAutocompleteItems),
minLength: 0
});
}
2017-11-05 01:59:43 +08:00
function getSelectedNotePath() {
const val = $autoComplete.val();
return link.getNodePathFromLabel(val);
}
function goToNote() {
const notePath = getSelectedNotePath();
if (notePath) {
treeService.activateNode(notePath);
$dialog.dialog('close');
2017-11-20 09:36:13 +08:00
}
}
2017-11-20 09:36:13 +08:00
$(document).bind('keydown', 'ctrl+j', e => {
showDialog();
2017-12-19 12:41:13 +08:00
e.preventDefault();
});
2017-11-20 09:36:13 +08:00
$form.submit(() => {
const action = $dialog.find("button:focus").val();
2017-11-20 09:36:13 +08:00
goToNote();
2017-11-05 01:59:43 +08:00
return false;
});
$showDialogButton.click(showDialog);
export default {
showDialog
};