Skip to content

Commit

Permalink
Merge pull request #2 from comatory/bug/multiple-clicks
Browse files Browse the repository at this point in the history
fix multiple clicks
  • Loading branch information
comatory authored Nov 19, 2023
2 parents fb2c3b1 + 93b3688 commit a943f1c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions js/ui/panel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,33 @@ function activatePanelButtonOnCoordinates(x, y) {
}

function attachMouseListeners() {
window.addEventListener("click", (event) => {
function handleMouseClick(event) {
activatePanelButtonOnCoordinates(event.clientX, event.clientY);
});
}

window.addEventListener("click", handleMouseClick);

return function dispose() {
window.removeEventListener("click", handleMouseClick);
};
}

function attachKeyboardListeners(state) {
window.addEventListener("keydown", (event) => {
function handleKeyDown(event) {
if (event.key !== "Enter") {
return;
}

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

activatePanelButtonOnCoordinates(cursor.x, cursor.y);
});
}

window.addEventListener("keydown", handleKeyDown);

return function dispose() {
window.removeEventListener("keydown", handleKeyDown);
};
}

function attachGamepadListeners(state) {
Expand Down

0 comments on commit a943f1c

Please sign in to comment.