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

49 lines
1.4 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 utils from "../services/utils.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");
export async function showDialog() {
utils.closeActiveDialog();
glob.activeDialog = $dialog;
2017-11-20 11:31:30 +08:00
$autoComplete.val('');
$dialog.modal();
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
.on('autocomplete:selected', function(event, suggestion, dataset) {
if (!suggestion.path) {
return false;
}
treeService.activateNote(suggestion.path);
});
noteAutocompleteService.showRecentNotes($autoComplete);
}
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
}
2019-11-10 00:39:48 +08:00
$showInFullTextButton.on('click', showInFullText);
2018-06-06 11:28:10 +08:00
utils.bindElShortcut($dialog, 'ctrl+return', showInFullText);