add suggestion filtering
This commit is contained in:
+24
-11
@@ -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];
|
||||
|
||||
let suggestions = [
|
||||
...(COMMANDS.get(oq.query)?.suggestions ??
|
||||
COMMANDS.get(parentKey)?.suggestions ??
|
||||
[]),
|
||||
];
|
||||
|
||||
for (const key of COMMANDS.keys()) {
|
||||
if (
|
||||
oq.search?.length > 1 &&
|
||||
suggestions.length < CONFIG.suggestionLimit
|
||||
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
|
||||
suggestions = oq.splitBy
|
||||
? res.map((search) => `${oq.key}${oq.splitBy}${search}`)
|
||||
: res
|
||||
)
|
||||
.slice(0, CONFIG.suggestionLimit);
|
||||
: res;
|
||||
|
||||
suggestions = suggestions.slice(0, CONFIG.suggestionLimit);
|
||||
}
|
||||
|
||||
const nq = Search.#parseQuery(this.#input.value);
|
||||
|
||||
Reference in New Issue
Block a user