remember last search in Jump To dialog when searching soon after the previous search

This commit is contained in:
zadam 2020-08-31 21:00:23 +02:00
parent 408ed8dbf0
commit 574b71de63

View File

@ -6,9 +6,10 @@ const $dialog = $("#jump-to-note-dialog");
const $autoComplete = $("#jump-to-note-autocomplete");
const $showInFullTextButton = $("#show-in-full-text-button");
export async function showDialog() {
$autoComplete.val('');
let lastOpenedTs = 0;
const KEEP_LAST_SEARCH_FOR_X_SECONDS = 120;
export async function showDialog() {
utils.openDialog($dialog);
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
@ -20,8 +21,21 @@ export async function showDialog() {
appContext.tabManager.getActiveTabContext().setNote(suggestion.notePath);
});
// if you open the Jump To dialog soon after using it previously it can often mean that you
// actually want to search for the same thing (e.g. you opened the wrong note at first try)
// so we'll keep the content.
// if it's outside of this time limit then we assume it's a completely new search and show recent notes instead.
if (Date.now() - lastOpenedTs > KEEP_LAST_SEARCH_FOR_X_SECONDS * 1000) {
noteAutocompleteService.showRecentNotes($autoComplete);
}
else {
$autoComplete
.trigger('focus')
.trigger('select');
}
lastOpenedTs = Date.now();
}
function showInFullText(e) {
// stop from propagating upwards (dangerous especially with ctrl+enter executable javascript notes)