From 574b71de63a16b9438276968020626bac6b47322 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 31 Aug 2020 21:00:23 +0200 Subject: [PATCH] remember last search in Jump To dialog when searching soon after the previous search --- src/public/app/dialogs/jump_to_note.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/public/app/dialogs/jump_to_note.js b/src/public/app/dialogs/jump_to_note.js index 5128593f4..037fd5b2d 100644 --- a/src/public/app/dialogs/jump_to_note.js +++ b/src/public/app/dialogs/jump_to_note.js @@ -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,7 +21,20 @@ export async function showDialog() { appContext.tabManager.getActiveTabContext().setNote(suggestion.notePath); }); - noteAutocompleteService.showRecentNotes($autoComplete); + // 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) {