Prioritize autocomplete dropdown over search results on Enter keypress
This commit is contained in:
+20
-19
@@ -586,15 +586,21 @@
|
|||||||
li.appendChild(badge);
|
li.appendChild(badge);
|
||||||
li.addEventListener("click", () => {
|
li.addEventListener("click", () => {
|
||||||
const input = document.getElementById("search-input");
|
const input = document.getElementById("search-input");
|
||||||
// Append tag: operator if not already typing one
|
|
||||||
const current = input.value;
|
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") {
|
if (ctx.type === "tag") {
|
||||||
// Replace the partial tag prefix
|
// 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 + " ";
|
input.value = before + item.tag + " ";
|
||||||
} else {
|
} 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 }));
|
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||||
this.hide();
|
this.hide();
|
||||||
@@ -4992,7 +4998,12 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
AutocompleteDropdown.navigateUp();
|
AutocompleteDropdown.navigateUp();
|
||||||
} else if (e.key === "Enter") {
|
} 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");
|
const results = document.querySelectorAll(".search-result-item");
|
||||||
if (results.length > 0 && _searchResultIdx >= 0) {
|
if (results.length > 0 && _searchResultIdx >= 0) {
|
||||||
const el = results[_searchResultIdx];
|
const el = results[_searchResultIdx];
|
||||||
@@ -5002,11 +5013,7 @@
|
|||||||
if (vault && path) { TabManager.openPreview(vault, path); e.preventDefault(); return; }
|
if (vault && path) { TabManager.openPreview(vault, path); e.preventDefault(); return; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (AutocompleteDropdown.selectActive()) {
|
// Third: execute search
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// No active item — execute search normally
|
|
||||||
AutocompleteDropdown.hide();
|
AutocompleteDropdown.hide();
|
||||||
const q = input.value.trim();
|
const q = input.value.trim();
|
||||||
if (q) {
|
if (q) {
|
||||||
@@ -5028,15 +5035,9 @@
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
} else if (e.key === "Enter") {
|
} else if (e.key === "Enter") {
|
||||||
// If search results are visible, open selected result
|
if (AutocompleteDropdown.isVisible() && AutocompleteDropdown.selectActive()) {
|
||||||
const results = document.querySelectorAll(".search-result-item");
|
e.preventDefault();
|
||||||
if (results.length > 0 && _searchResultIdx >= 0) {
|
return;
|
||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const q = input.value.trim();
|
const q = input.value.trim();
|
||||||
if (q) {
|
if (q) {
|
||||||
|
|||||||
@@ -3283,9 +3283,6 @@ body.resizing-v {
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
|
||||||
z-index: 200;
|
z-index: 200;
|
||||||
max-height: 380px;
|
|
||||||
overflow-y: auto;
|
|
||||||
overflow-x: hidden;
|
|
||||||
}
|
}
|
||||||
.search-dropdown[hidden] {
|
.search-dropdown[hidden] {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
Reference in New Issue
Block a user