2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-05 01:59:43 +08:00
|
|
|
const jumpToNote = (function() {
|
2018-02-10 21:44:34 +08:00
|
|
|
const $dialog = $("#jump-to-note-dialog");
|
|
|
|
const $autoComplete = $("#jump-to-note-autocomplete");
|
|
|
|
const $form = $("#jump-to-note-form");
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-20 09:36:13 +08:00
|
|
|
async function showDialog() {
|
2018-02-10 21:44:34 +08:00
|
|
|
glob.activeDialog = $dialog;
|
2017-11-05 05:03:15 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$autoComplete.val('');
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$dialog.dialog({
|
2017-11-05 01:59:43 +08:00
|
|
|
modal: true,
|
|
|
|
width: 800
|
|
|
|
});
|
2017-10-11 08:37:45 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
await $autoComplete.autocomplete({
|
2018-01-23 12:18:08 +08:00
|
|
|
source: await stopWatch("building autocomplete", noteTree.getAutocompleteItems),
|
2017-11-05 01:59:43 +08:00
|
|
|
minLength: 0
|
|
|
|
});
|
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-20 11:31:30 +08:00
|
|
|
function getSelectedNotePath() {
|
2018-02-10 21:44:34 +08:00
|
|
|
const val = $autoComplete.val();
|
2017-11-20 11:31:30 +08:00
|
|
|
return link.getNodePathFromLabel(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
function goToNote() {
|
|
|
|
const notePath = getSelectedNotePath();
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-20 09:36:13 +08:00
|
|
|
if (notePath) {
|
|
|
|
noteTree.activateNode(notePath);
|
2017-11-05 01:59:43 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$dialog.dialog('close');
|
2017-11-05 01:59:43 +08:00
|
|
|
}
|
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
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$form.submit(() => {
|
|
|
|
const action = $dialog.find("button:focus").val();
|
2017-11-20 09:36:13 +08:00
|
|
|
|
2017-12-22 11:03:13 +08:00
|
|
|
goToNote();
|
2017-11-05 01:59:43 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 01:59:43 +08:00
|
|
|
return {
|
|
|
|
showDialog
|
|
|
|
};
|
|
|
|
})();
|