Prioritize autocomplete dropdown over search results on Enter keypress
This commit is contained in:
parent
8055b20e5f
commit
a7c719afb1
@ -586,15 +586,21 @@
|
||||
li.appendChild(badge);
|
||||
li.addEventListener("click", () => {
|
||||
const input = document.getElementById("search-input");
|
||||
// Append tag: operator if not already typing one
|
||||
const current = input.value;
|
||||
const ctx = QueryParser.getContext(current, input.selectionStart);
|
||||
const cursorPos = input.selectionStart;
|
||||
const ctx = QueryParser.getContext(current, cursorPos);
|
||||
if (ctx.type === "tag") {
|
||||
// Replace the partial tag prefix
|
||||
const before = current.slice(0, input.selectionStart - ctx.prefix.length);
|
||||
const before = current.slice(0, cursorPos - ctx.prefix.length);
|
||||
input.value = before + item.tag + " ";
|
||||
} else {
|
||||
input.value = (current ? current + " " : "") + "tag:" + item.tag + " ";
|
||||
// Replace the last word with tag: operator
|
||||
const words = current.trim().split(/\s+/);
|
||||
if (words.length > 0 && ctx.prefix && ctx.prefix.length > 0) {
|
||||
words[words.length - 1] = ""; // remove last partial word
|
||||
}
|
||||
const base = words.filter(w => w).join(" ");
|
||||
input.value = (base ? base + " " : "") + "tag:" + item.tag + " ";
|
||||
}
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
this.hide();
|
||||
@ -4992,7 +4998,12 @@
|
||||
e.preventDefault();
|
||||
AutocompleteDropdown.navigateUp();
|
||||
} else if (e.key === "Enter") {
|
||||
// If search results are visible, open the selected result
|
||||
// First: check dropdown suggestions (higher priority than search results)
|
||||
if (AutocompleteDropdown.isVisible() && AutocompleteDropdown.selectActive()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
// Second: navigate search results if visible
|
||||
const results = document.querySelectorAll(".search-result-item");
|
||||
if (results.length > 0 && _searchResultIdx >= 0) {
|
||||
const el = results[_searchResultIdx];
|
||||
@ -5002,11 +5013,7 @@
|
||||
if (vault && path) { TabManager.openPreview(vault, path); e.preventDefault(); return; }
|
||||
}
|
||||
}
|
||||
if (AutocompleteDropdown.selectActive()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
// No active item — execute search normally
|
||||
// Third: execute search
|
||||
AutocompleteDropdown.hide();
|
||||
const q = input.value.trim();
|
||||
if (q) {
|
||||
@ -5028,15 +5035,9 @@
|
||||
e.stopPropagation();
|
||||
}
|
||||
} else if (e.key === "Enter") {
|
||||
// If search results are visible, open selected result
|
||||
const results = document.querySelectorAll(".search-result-item");
|
||||
if (results.length > 0 && _searchResultIdx >= 0) {
|
||||
const el = results[_searchResultIdx];
|
||||
if (el) {
|
||||
const vault = el.dataset.vault;
|
||||
const path = el.dataset.path;
|
||||
if (vault && path) { TabManager.openPreview(vault, path); e.preventDefault(); return; }
|
||||
}
|
||||
if (AutocompleteDropdown.isVisible() && AutocompleteDropdown.selectActive()) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
const q = input.value.trim();
|
||||
if (q) {
|
||||
|
||||
@ -3283,9 +3283,6 @@ body.resizing-v {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
|
||||
z-index: 200;
|
||||
max-height: 380px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
.search-dropdown[hidden] {
|
||||
display: none;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user