DoorChooser keyboard input method

This commit is contained in:
Jörn-Michael Miehe 2023-02-02 23:16:44 +00:00
parent 1ab02e6905
commit 67c371b483

View file

@ -3,8 +3,11 @@
<div class="content"> <div class="content">
<p class="title is-5">Steuerung</p> <p class="title is-5">Steuerung</p>
<ul> <ul>
<li>Linksklick: Türchen hochzählen</li> <li>Linksklick: Türchen auswählen</li>
<li>Rechtsklick: Türchen runterzählen</li> <li>Tastatur [0]-[9], [Rücktaste]: Tag eingeben</li>
<li>Tastatur [Enter]: Tag speichern</li>
<li>Tastatur [Esc]: Eingabe Abbrechen</li>
<li>Tastatur [Entf]: Tag entfernen</li>
</ul> </ul>
</div> </div>
<figure class="image"> <figure class="image">
@ -18,10 +21,8 @@
/> />
<SVGRect <SVGRect
:rectangle="door.position" :rectangle="door.position"
:focused="door.day >= 0" :focused="index === focused"
@click.left="door.day++" @click.left="click_door(index)"
@click.right="door.day--"
style="cursor: pointer"
/> />
</template> </template>
</ThouCanvas> </ThouCanvas>
@ -50,6 +51,53 @@ import SVGRectText from "../rects/SVGRectText.vue";
}) })
export default class extends Vue { export default class extends Vue {
private doors!: Door[]; private doors!: Door[];
private focused = -1;
private click_door(index: number) {
if (this.focused >= 0) {
return;
}
this.focused = index;
const listener = (() => {
let old_day = this.doors[index].day;
let num_input = "";
return (event: KeyboardEvent) => {
if (event.key >= "0" && event.key <= "9") {
// number input
num_input += event.key;
this.doors[this.focused].day = Number(num_input);
} else if (event.key === "Backspace") {
// remove char
num_input = num_input.slice(0, -1);
this.doors[this.focused].day = Number(num_input);
} else if (event.key === "Enter") {
// accept
this.focused = -1;
window.removeEventListener("keydown", listener);
} else if (event.key === "Escape") {
// abort
this.doors[this.focused].day = old_day;
this.focused = -1;
window.removeEventListener("keydown", listener);
} else if (event.key === "Delete") {
// delete
this.doors[this.focused].day = -1;
this.focused = -1;
window.removeEventListener("keydown", listener);
}
};
})();
window.addEventListener("keydown", listener);
}
public beforeUnmount() { public beforeUnmount() {
this.$emit("update:doors", this.doors); this.$emit("update:doors", this.doors);
@ -60,5 +108,9 @@ export default class extends Vue {
<style lang="scss" scoped> <style lang="scss" scoped>
section > figure { section > figure {
user-select: none; user-select: none;
svg > rect {
cursor: pointer;
}
} }
</style> </style>