added keybinds enter and space to move to next question/reveal answer

This commit is contained in:
Lutu-gl 2025-03-12 11:45:40 +01:00
parent 2bf749a02e
commit 9ac5755406

14
main.ts
View file

@ -104,9 +104,22 @@ class QuestionsModal extends Modal {
bgEl.style.backdropFilter = "none";
bgEl.style.backgroundColor = "";
}
this.registerKeys();
this.render();
}
registerKeys() {
this.handleKeyPress = this.handleKeyPress.bind(this);
window.addEventListener("keydown", this.handleKeyPress);
}
handleKeyPress(event: KeyboardEvent) {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
this.toggleAnswer();
}
}
render() {
const { contentEl } = this;
contentEl.empty();
@ -173,6 +186,7 @@ class QuestionsModal extends Modal {
const { contentEl } = this;
contentEl.empty();
this.component.unload();
window.removeEventListener("keydown", this.handleKeyPress);
}
}