mirror of
https://github.com/xvvvyz/tilde.git
synced 2026-03-11 14:44:24 +00:00
only limit suggestions when using ddg autocomplete
This commit is contained in:
parent
7392c9d1bb
commit
cb7298c2f3
1 changed files with 13 additions and 9 deletions
22
index.html
22
index.html
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue