From 80f6a9431985218f5d8f3701edf6ddc41ace1c01 Mon Sep 17 00:00:00 2001 From: cade Date: Mon, 13 Apr 2026 10:58:48 -0700 Subject: [PATCH] fix rapid keypress/escape race condition --- index.html | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index e084db6..069717b 100644 --- a/index.html +++ b/index.html @@ -490,6 +490,7 @@ #input; #suggestions; #lastSuggestions = []; + #closeController = null; constructor() { super(); @@ -587,11 +588,15 @@ }; #open() { + this.#closeController?.abort(); + this.#closeController = null; this.#dialog.show(); requestAnimationFrame(() => this.#dialog.classList.add('visible')); } #close() { + this.#closeController?.abort(); + this.#closeController = new AbortController(); this.#dialog.classList.remove('visible'); this.#input.value = ''; this.#input.blur(); @@ -603,8 +608,10 @@ if (!this.#dialog.classList.contains('visible')) { this.#dialog.close(); } + + this.#closeController = null; }, - { once: true } + { once: true, signal: this.#closeController.signal } ); } @@ -717,7 +724,21 @@ #onKeydown = (e) => { if (!this.#dialog.classList.contains('visible')) { - if (e.key === 'Escape') return; + if (e.key === 'Escape') { + if (this.#dialog.open) { + this.#closeController?.abort(); + this.#closeController = null; + this.#input.value = ''; + this.#input.blur(); + this.#dialog.close(); + this.#suggestions.innerHTML = ''; + } + + return; + } + + this.#closeController?.abort(); + this.#closeController = null; this.#dialog.show(); this.#input.focus();