mirror of
https://github.com/lutu-gl/Obsidian-Minimal-Quiz.git
synced 2026-07-22 05:42:37 +00:00
added keybinds enter and space to move to next question/reveal answer
This commit is contained in:
parent
2bf749a02e
commit
9ac5755406
1 changed files with 14 additions and 0 deletions
14
main.ts
14
main.ts
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue