From d55fdb8babab652c2281f08e0d58c28710eeb29d Mon Sep 17 00:00:00 2001 From: Cade Scroggins Date: Sun, 12 Feb 2023 12:22:27 -0800 Subject: [PATCH] do not render suggestions for an old query --- index.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 1ca0c5c..d152f27 100644 --- a/index.html +++ b/index.html @@ -647,22 +647,24 @@ } #onInput = async () => { - const q = Search.#parseQuery(this.#refs.input.value); + const oq = Search.#parseQuery(this.#refs.input.value); - if (!q.query) { + if (!oq.query) { this.#close(); return; } - let suggestions = COMMANDS.get(q.query)?.suggestions ?? []; + let suggestions = COMMANDS.get(oq.query)?.suggestions ?? []; - if (q.search && suggestions.length < CONFIG.suggestionLimit) { - const res = await Search.#fetchDuckDuckGoSuggestions(q.search); - const formatted = Search.#attachSearchPrefix(res, q); + if (oq.search && suggestions.length < CONFIG.suggestionLimit) { + const res = await Search.#fetchDuckDuckGoSuggestions(oq.search); + const formatted = Search.#attachSearchPrefix(res, oq); suggestions = suggestions.concat(formatted); } - this.#renderSuggestions(suggestions, q.query); + const nq = Search.#parseQuery(this.#refs.input.value); + if (nq.query !== oq.query) return; + this.#renderSuggestions(suggestions, oq.query); }; #onKeydown = (e) => {