From cdb6a8796082349d966a8a4c44f0ae745e5fff6b Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sun, 17 May 2026 17:50:31 +0200 Subject: [PATCH] fix(console): apply review fixes for first-keystroke race and exact-match Tab Co-Authored-By: Claude Sonnet 4.6 --- l4d2web/l4d2web/static/js/console-autocomplete.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/l4d2web/l4d2web/static/js/console-autocomplete.js b/l4d2web/l4d2web/static/js/console-autocomplete.js index 3dd9ca0..7dc6fe4 100644 --- a/l4d2web/l4d2web/static/js/console-autocomplete.js +++ b/l4d2web/l4d2web/static/js/console-autocomplete.js @@ -93,6 +93,9 @@ function bindConsoleAutocomplete(form) { const chosen = items[highlightIdx]; const slice = firstTokenSlice(input.value, input.selectionStart || 0); if (!slice) return; + // If the first token is already exactly the chosen name, accepting it + // would be a no-op; close the dropdown so Tab feels responsive. + if (slice.token === chosen.name) { close(); return; } const before = input.value.slice(0, slice.from); const after = input.value.slice(slice.to); input.value = before + chosen.name + after; @@ -116,6 +119,9 @@ function bindConsoleAutocomplete(form) { input.addEventListener("focus", async () => { if (!vocab) { vocab = await loadVocab(); + // If the user already typed during the fetch, rank now so the + // dropdown doesn't appear to lag a keystroke behind on cold load. + if (vocab && document.activeElement === input) recompute(); } }, { once: true });