[Editor] Remove ColorPicker event listeners with AbortSignal.any() (PR 18586 follow-up)

Also, removes another "unnecessary" bound-method.
This commit is contained in:
Jonas Jenwald 2024-10-09 10:58:35 +02:00
parent 233ac1773d
commit 14537d1412

View File

@ -18,10 +18,6 @@ import { KeyboardManager } from "./tools.js";
import { noContextMenu } from "../display_utils.js"; import { noContextMenu } from "../display_utils.js";
class ColorPicker { class ColorPicker {
#boundKeyDown = this.#keyDown.bind(this);
#boundPointerDown = this.#pointerDown.bind(this);
#button = null; #button = null;
#buttonSwatch = null; #buttonSwatch = null;
@ -38,6 +34,8 @@ class ColorPicker {
#eventBus; #eventBus;
#openDropdownAC = null;
#uiManager = null; #uiManager = null;
#type; #type;
@ -101,7 +99,7 @@ class ColorPicker {
button.setAttribute("aria-haspopup", true); button.setAttribute("aria-haspopup", true);
const signal = this.#uiManager._signal; const signal = this.#uiManager._signal;
button.addEventListener("click", this.#openDropdown.bind(this), { signal }); button.addEventListener("click", this.#openDropdown.bind(this), { signal });
button.addEventListener("keydown", this.#boundKeyDown, { signal }); button.addEventListener("keydown", this.#keyDown.bind(this), { signal });
const swatch = (this.#buttonSwatch = document.createElement("span")); const swatch = (this.#buttonSwatch = document.createElement("span"));
swatch.className = "swatch"; swatch.className = "swatch";
swatch.setAttribute("aria-hidden", true); swatch.setAttribute("aria-hidden", true);
@ -145,7 +143,7 @@ class ColorPicker {
div.append(button); div.append(button);
} }
div.addEventListener("keydown", this.#boundKeyDown, { signal }); div.addEventListener("keydown", this.#keyDown.bind(this), { signal });
return div; return div;
} }
@ -225,9 +223,14 @@ class ColorPicker {
return; return;
} }
this.#dropdownWasFromKeyboard = event.detail === 0; this.#dropdownWasFromKeyboard = event.detail === 0;
window.addEventListener("pointerdown", this.#boundPointerDown, {
signal: this.#uiManager._signal, if (!this.#openDropdownAC) {
}); this.#openDropdownAC = new AbortController();
window.addEventListener("pointerdown", this.#pointerDown.bind(this), {
signal: this.#uiManager.combinedSignal(this.#openDropdownAC),
});
}
if (this.#dropdown) { if (this.#dropdown) {
this.#dropdown.classList.remove("hidden"); this.#dropdown.classList.remove("hidden");
return; return;
@ -245,7 +248,8 @@ class ColorPicker {
hideDropdown() { hideDropdown() {
this.#dropdown?.classList.add("hidden"); this.#dropdown?.classList.add("hidden");
window.removeEventListener("pointerdown", this.#boundPointerDown); this.#openDropdownAC?.abort();
this.#openDropdownAC = null;
} }
get #isDropdownVisible() { get #isDropdownVisible() {