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
No known key found for this signature in database
GPG key ID: 6AC5A902158265D0

View file

@ -44,7 +44,7 @@
commandSearchDelimiter: ' ',
defaultSearchTemplate: 'https://duckduckgo.com/?q={}',
openLinksInNewTab: true,
suggestionLimit: 5,
suggestionLimit: 4,
};
// prettier-ignore
@ -441,14 +441,19 @@
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);
suggestions = suggestions.concat(
oq.splitBy
? res.map((search) => `${oq.key}${oq.splitBy}${search}`)
: res
);
suggestions = suggestions
.concat(
oq.splitBy
? res.map((search) => `${oq.key}${oq.splitBy}${search}`)
: res
)
.slice(0, CONFIG.suggestionLimit);
}
const nq = Search.#parseQuery(this.#input.value);
@ -505,10 +510,9 @@
#renderSuggestions(suggestions, query) {
this.#suggestions.innerHTML = '';
const sliced = suggestions.slice(0, CONFIG.suggestionLimit);
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 ref = clone.querySelector('.suggestion');
ref.dataset.index = index;