2018-03-26 01:41:29 +08:00
|
|
|
import treeService from '../services/tree.js';
|
2018-06-06 11:28:10 +08:00
|
|
|
import searchNotesService from '../services/search_notes.js';
|
2018-11-07 16:51:14 +08:00
|
|
|
import noteAutocompleteService from '../services/note_autocomplete.js';
|
2019-06-11 04:45:03 +08:00
|
|
|
import utils from "../services/utils.js";
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
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");
|
2018-11-07 07:23:50 +08:00
|
|
|
|
2019-08-21 03:40:47 +08:00
|
|
|
export async function showDialog() {
|
2019-06-11 04:45:03 +08:00
|
|
|
utils.closeActiveDialog();
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
glob.activeDialog = $dialog;
|
2017-11-20 11:31:30 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$autoComplete.val('');
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-11-06 22:25:07 +08:00
|
|
|
$dialog.modal();
|
2018-03-25 23:09:17 +08:00
|
|
|
|
2018-11-14 18:28:52 +08:00
|
|
|
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
|
2018-11-07 16:51:14 +08:00
|
|
|
.on('autocomplete:selected', function(event, suggestion, dataset) {
|
|
|
|
if (!suggestion.path) {
|
|
|
|
return false;
|
2018-07-26 22:05:09 +08:00
|
|
|
}
|
2018-08-17 03:02:42 +08:00
|
|
|
|
2018-11-07 16:51:14 +08:00
|
|
|
treeService.activateNote(suggestion.path);
|
|
|
|
});
|
2018-03-25 23:09:17 +08:00
|
|
|
|
2018-11-07 16:51:14 +08:00
|
|
|
noteAutocompleteService.showRecentNotes($autoComplete);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
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);
|
|
|
|
|
2018-11-07 00:47:40 +08:00
|
|
|
$dialog.modal('hide');
|
2018-06-06 11:28:10 +08:00
|
|
|
}
|
|
|
|
|
2018-11-07 16:51:14 +08:00
|
|
|
|
2018-06-06 11:28:10 +08:00
|
|
|
$showInFullTextButton.click(showInFullText);
|
|
|
|
|
2019-08-13 04:41:53 +08:00
|
|
|
utils.bindElShortcut($dialog, 'ctrl+return', showInFullText);
|