From 3b17c68a0450f2397bae1925a438c43ba943c73f Mon Sep 17 00:00:00 2001 From: cade Date: Sat, 21 Mar 2026 00:15:45 +0000 Subject: [PATCH] add suggestion filtering --- index.html | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index d5bc40d..0aafda7 100644 --- a/index.html +++ b/index.html @@ -49,8 +49,8 @@ // prettier-ignore const COMMANDS = new Map([ - ['a', { name: 'AI', suggestions: ['a/chat', 'a/gemini', 'a/grok', 'a/lumo'], url: 'https://claude.ai/new' }], - ['a/chat', { url: 'https://chatgpt.com' }], + ['a', { name: 'AI', suggestions: ['a/chatgpt', 'a/gemini', 'a/grok', 'a/lumo'], url: 'https://claude.ai/new' }], + ['a/chatgpt', { url: 'https://chatgpt.com' }], ['a/gemini', { url: 'https://gemini.google.com' }], ['a/grok', { url: 'https://grok.com' }], ['a/lumo', { url: 'https://lumo.proton.me/u/0' }], @@ -451,21 +451,34 @@ return; } - let suggestions = COMMANDS.get(oq.query)?.suggestions ?? []; + const parentKey = oq.query.split(CONFIG.commandPathDelimiter)[0]; - if ( - oq.search?.length > 1 && - suggestions.length < CONFIG.suggestionLimit - ) { + let suggestions = [ + ...(COMMANDS.get(oq.query)?.suggestions ?? + COMMANDS.get(parentKey)?.suggestions ?? + []), + ]; + + for (const key of COMMANDS.keys()) { + if ( + key.startsWith(oq.query) && + key !== oq.query && + !suggestions.includes(key) + ) { + suggestions.push(key); + } + } + + suggestions = suggestions.filter((s) => s.startsWith(oq.query)); + + if (oq.search?.length > 1 && suggestions.length === 0) { const res = await Search.#fetchDuckDuckGoSuggestions(oq.search); - suggestions = suggestions - .concat( - oq.splitBy - ? res.map((search) => `${oq.key}${oq.splitBy}${search}`) - : res - ) - .slice(0, CONFIG.suggestionLimit); + suggestions = oq.splitBy + ? res.map((search) => `${oq.key}${oq.splitBy}${search}`) + : res; + + suggestions = suggestions.slice(0, CONFIG.suggestionLimit); } const nq = Search.#parseQuery(this.#input.value);