only limit suggestions when using ddg autocomplete

This commit is contained in:
cade
2025-07-16 11:46:33 -07:00
parent 7392c9d1bb
commit cb7298c2f3
+10 -6
View File
@@ -44,7 +44,7 @@
commandSearchDelimiter: ' ', commandSearchDelimiter: ' ',
defaultSearchTemplate: 'https://duckduckgo.com/?q={}', defaultSearchTemplate: 'https://duckduckgo.com/?q={}',
openLinksInNewTab: true, openLinksInNewTab: true,
suggestionLimit: 5, suggestionLimit: 4,
}; };
// prettier-ignore // prettier-ignore
@@ -441,14 +441,19 @@
let suggestions = COMMANDS.get(oq.query)?.suggestions ?? []; let suggestions = COMMANDS.get(oq.query)?.suggestions ?? [];
if (oq.search && suggestions.length < CONFIG.suggestionLimit) { if (
oq.search?.length > 1 &&
suggestions.length < CONFIG.suggestionLimit
) {
const res = await Search.#fetchDuckDuckGoSuggestions(oq.search); const res = await Search.#fetchDuckDuckGoSuggestions(oq.search);
suggestions = suggestions.concat( suggestions = suggestions
.concat(
oq.splitBy oq.splitBy
? res.map((search) => `${oq.key}${oq.splitBy}${search}`) ? res.map((search) => `${oq.key}${oq.splitBy}${search}`)
: res : res
); )
.slice(0, CONFIG.suggestionLimit);
} }
const nq = Search.#parseQuery(this.#input.value); const nq = Search.#parseQuery(this.#input.value);
@@ -505,10 +510,9 @@
#renderSuggestions(suggestions, query) { #renderSuggestions(suggestions, query) {
this.#suggestions.innerHTML = ''; this.#suggestions.innerHTML = '';
const sliced = suggestions.slice(0, CONFIG.suggestionLimit);
const template = document.getElementById('suggestion-template'); const template = document.getElementById('suggestion-template');
for (const [index, suggestion] of sliced.entries()) { for (const [index, suggestion] of suggestions.entries()) {
const clone = template.content.cloneNode(true); const clone = template.content.cloneNode(true);
const ref = clone.querySelector('.suggestion'); const ref = clone.querySelector('.suggestion');
ref.dataset.index = index; ref.dataset.index = index;