Add full text search in autocomplete results

This commit is contained in:
SiriusXT 2024-11-24 13:10:33 +08:00
parent 5370e1e27c
commit 1d1c7eb2ca

View File

@ -94,21 +94,21 @@ function showRecentNotes($el) {
$el.setSelectedNotePath(""); $el.setSelectedNotePath("");
$el.autocomplete("val", ""); $el.autocomplete("val", "");
$el.autocomplete('open');
$el.trigger('focus'); $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){ function fullTextSearch($el,options){
const searchString = $el.autocomplete("val") const searchString = $el.autocomplete('val');
if (searchString.trim().length >= 1) {
const originalFastSearch = options.fastSearch;
clearText($el); clearText($el);
options.fastSearch = false; options.fastSearch = false;
$el.autocomplete("val", searchString); $el.autocomplete('val', searchString);
$el.autocomplete('open'); $el.autocomplete('open');
options.fastSearch = true; $el.trigger('focus');
options.fastSearch = originalFastSearch;
}
} }
function initNoteAutocomplete($el, options) { function initNoteAutocomplete($el, options) {
@ -120,6 +120,7 @@ function initNoteAutocomplete($el, options) {
} }
options = options || {}; options = options || {};
options.fastSearch = true; // Perform fast search by default
$el.addClass("note-autocomplete-input"); $el.addClass("note-autocomplete-input");
@ -133,7 +134,7 @@ function initNoteAutocomplete($el, options) {
const $fullTextSearchButton = $("<button>") const $fullTextSearchButton = $("<button>")
.addClass("input-group-text full-text-search-button bx bx-search") .addClass("input-group-text full-text-search-button bx bx-search")
.prop("title", "Full text search. (Shift+Enter)"); .prop("title", "Full text search (Shift+Enter)");
const $goToSelectedNoteButton = $("<button>") const $goToSelectedNoteButton = $("<button>")
.addClass("input-group-text go-to-selected-note-button bx bx-arrow-to-right"); .addClass("input-group-text go-to-selected-note-button bx bx-arrow-to-right");
@ -183,7 +184,6 @@ function initNoteAutocomplete($el, options) {
} }
}); });
options.fastSearch = true; // Perform fast search by default
$el.autocomplete({ $el.autocomplete({
...autocompleteOptions, ...autocompleteOptions,
appendTo: document.querySelector('body'), appendTo: document.querySelector('body'),