fix rapid keypress/escape race condition
This commit is contained in:
+23
-2
@@ -490,6 +490,7 @@
|
|||||||
#input;
|
#input;
|
||||||
#suggestions;
|
#suggestions;
|
||||||
#lastSuggestions = [];
|
#lastSuggestions = [];
|
||||||
|
#closeController = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -587,11 +588,15 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
#open() {
|
#open() {
|
||||||
|
this.#closeController?.abort();
|
||||||
|
this.#closeController = null;
|
||||||
this.#dialog.show();
|
this.#dialog.show();
|
||||||
requestAnimationFrame(() => this.#dialog.classList.add('visible'));
|
requestAnimationFrame(() => this.#dialog.classList.add('visible'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#close() {
|
#close() {
|
||||||
|
this.#closeController?.abort();
|
||||||
|
this.#closeController = new AbortController();
|
||||||
this.#dialog.classList.remove('visible');
|
this.#dialog.classList.remove('visible');
|
||||||
this.#input.value = '';
|
this.#input.value = '';
|
||||||
this.#input.blur();
|
this.#input.blur();
|
||||||
@@ -603,8 +608,10 @@
|
|||||||
if (!this.#dialog.classList.contains('visible')) {
|
if (!this.#dialog.classList.contains('visible')) {
|
||||||
this.#dialog.close();
|
this.#dialog.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#closeController = null;
|
||||||
},
|
},
|
||||||
{ once: true }
|
{ once: true, signal: this.#closeController.signal }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,7 +724,21 @@
|
|||||||
|
|
||||||
#onKeydown = (e) => {
|
#onKeydown = (e) => {
|
||||||
if (!this.#dialog.classList.contains('visible')) {
|
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.#dialog.show();
|
||||||
this.#input.focus();
|
this.#input.focus();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user