Skip to content

Commit a943f1c

Browse files
authored
Merge pull request #2 from comatory/bug/multiple-clicks
fix multiple clicks
2 parents fb2c3b1 + 93b3688 commit a943f1c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

js/ui/panel.mjs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,33 @@ function activatePanelButtonOnCoordinates(x, y) {
5050
}
5151

5252
function attachMouseListeners() {
53-
window.addEventListener("click", (event) => {
53+
function handleMouseClick(event) {
5454
activatePanelButtonOnCoordinates(event.clientX, event.clientY);
55-
});
55+
}
56+
57+
window.addEventListener("click", handleMouseClick);
58+
59+
return function dispose() {
60+
window.removeEventListener("click", handleMouseClick);
61+
};
5662
}
5763

5864
function attachKeyboardListeners(state) {
59-
window.addEventListener("keydown", (event) => {
65+
function handleKeyDown(event) {
6066
if (event.key !== "Enter") {
6167
return;
6268
}
6369

6470
const cursor = state.get((prevState) => prevState.cursor);
6571

6672
activatePanelButtonOnCoordinates(cursor.x, cursor.y);
67-
});
73+
}
74+
75+
window.addEventListener("keydown", handleKeyDown);
76+
77+
return function dispose() {
78+
window.removeEventListener("keydown", handleKeyDown);
79+
};
6880
}
6981

7082
function attachGamepadListeners(state) {

0 commit comments

Comments
 (0)