diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index 5dbb25c03..648faac8a 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -30,10 +30,22 @@ async function autocompleteSourceForCKEditor(queryText) { } async function autocompleteSource(term, cb, options = {}) { + const fastSearch = options.fastSearch === false ? false : true; + if (fastSearch === false) { + if (term.trim().length === 0){ + return; + } + cb( + [{ + noteTitle: term, + highlightedNotePathTitle: `Searching...` + }] + ); + } + const activeNoteId = appContext.tabManager.getActiveContextNoteId(); - let results = await server.get(`autocomplete?query=${encodeURIComponent(term)}&activeNoteId=${activeNoteId}`); - + let results = await server.get(`autocomplete?query=${encodeURIComponent(term)}&activeNoteId=${activeNoteId}&fastSearch=${fastSearch}`); if (term.trim().length >= 1 && options.allowCreatingNotes) { results = [ { @@ -45,7 +57,7 @@ async function autocompleteSource(term, cb, options = {}) { ].concat(results); } - if (term.trim().length >= 1 && options.allowSearchNotes) { + if (term.trim().length >= 1 && options.allowJumpToSearchNotes) { results = results.concat([ { action: 'search-notes', @@ -95,12 +107,22 @@ function showRecentNotes($el) { $el.setSelectedNotePath(""); $el.autocomplete("val", ""); + $el.autocomplete('open'); $el.trigger('focus'); +} - // simulate pressing down arrow to trigger autocomplete - const e = $.Event('keydown'); - e.which = 40; // arrow down - $el.trigger(e); +function fullTextSearch($el, options){ + const searchString = $el.autocomplete('val'); + if (options.fastSearch === false || searchString.trim().length === 0) { + return; + } + $el.trigger('focus'); + options.fastSearch = false; + $el.autocomplete('val', ''); + $el.setSelectedNotePath(""); + $el.autocomplete('val', searchString); + // Set a delay to avoid resetting to true before full text search (await server.get) is called. + setTimeout(() => { options.fastSearch = true; }, 100); } function initNoteAutocomplete($el, options) { @@ -123,10 +145,14 @@ function initNoteAutocomplete($el, options) { .addClass("input-group-text show-recent-notes-button bx bx-time") .prop("title", "Show recent notes"); + const $fullTextSearchButton = $("