fix(console): apply review fixes for first-keystroke race and exact-match Tab

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mwiegand 2026-05-17 17:50:31 +02:00
parent 40961eacdd
commit cdb6a87960
No known key found for this signature in database

View file

@ -93,6 +93,9 @@ function bindConsoleAutocomplete(form) {
const chosen = items[highlightIdx]; const chosen = items[highlightIdx];
const slice = firstTokenSlice(input.value, input.selectionStart || 0); const slice = firstTokenSlice(input.value, input.selectionStart || 0);
if (!slice) return; 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 before = input.value.slice(0, slice.from);
const after = input.value.slice(slice.to); const after = input.value.slice(slice.to);
input.value = before + chosen.name + after; input.value = before + chosen.name + after;
@ -116,6 +119,9 @@ function bindConsoleAutocomplete(form) {
input.addEventListener("focus", async () => { input.addEventListener("focus", async () => {
if (!vocab) { if (!vocab) {
vocab = await loadVocab(); 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 }); }, { once: true });