From 0b251530fa0ee61edc8dcc9235033abb73afc614 Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 10 Jan 2019 21:04:06 +0100 Subject: [PATCH] open recent notes autocomplete by focus so it is then closed with blur, fixes #272 --- src/public/javascripts/dialogs/jump_to_note.js | 2 -- src/public/javascripts/services/note_autocomplete.js | 10 ++++++++-- src/public/javascripts/services/search_notes.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/public/javascripts/dialogs/jump_to_note.js b/src/public/javascripts/dialogs/jump_to_note.js index f74fe0e7b..063434d2a 100644 --- a/src/public/javascripts/dialogs/jump_to_note.js +++ b/src/public/javascripts/dialogs/jump_to_note.js @@ -6,8 +6,6 @@ const $dialog = $("#jump-to-note-dialog"); const $autoComplete = $("#jump-to-note-autocomplete"); const $showInFullTextButton = $("#show-in-full-text-button"); -$dialog.on("shown.bs.modal", e => $autoComplete.focus()); - async function showDialog() { glob.activeDialog = $dialog; diff --git a/src/public/javascripts/services/note_autocomplete.js b/src/public/javascripts/services/note_autocomplete.js index 00bf55f3b..fd7f166c9 100644 --- a/src/public/javascripts/services/note_autocomplete.js +++ b/src/public/javascripts/services/note_autocomplete.js @@ -28,7 +28,7 @@ function clearText($el) { function showRecentNotes($el) { $el.setSelectedPath(""); $el.autocomplete("val", ""); - $el.autocomplete("open"); + $el.focus(); } function initNoteAutocomplete($el, options) { @@ -61,7 +61,13 @@ function initNoteAutocomplete($el, options) { $clearTextButton.click(() => clearText($el)); - $showRecentNotesButton.click(() => showRecentNotes($el)); + $showRecentNotesButton.click(e => { + showRecentNotes($el); + + // this will cause the click not give focus to the "show recent notes" button + // this is important because otherwise input will lose focus immediatelly and not show the results + return false; + }); $goToSelectedNoteButton.click(() => { if ($el.hasClass("disabled")) { diff --git a/src/public/javascripts/services/search_notes.js b/src/public/javascripts/services/search_notes.js index ecb4deb0e..916391960 100644 --- a/src/public/javascripts/services/search_notes.js +++ b/src/public/javascripts/services/search_notes.js @@ -87,7 +87,7 @@ $searchInput.keyup(e => { if (e && e.which === $.ui.keyCode.ENTER) { doSearch(); } -}).focus(); +}); $doSearchButton.click(() => doSearch()); // keep long form because of argument $resetSearchButton.click(resetSearch);