fix(web): cursor focusing

This commit is contained in:
2026-08-22 22:36:34 +02:00
parent ab79575942
commit ab7c9b5670
+18 -10
View File
@@ -37,8 +37,9 @@
if (event.key === "Backspace") {
if (letters[cursor] === "" && cursor > 0) {
cursor--;
inputs[cursor].focus();
const nc = cursor - 1;
inputs[nc].focus(); // Focusing / bluring resets cursor temporarily
cursor = nc;
}
if (active) {
@@ -47,13 +48,15 @@
}
if (event.key === "ArrowLeft") {
cursor = Math.max(0, cursor - 1);
inputs[cursor].focus();
const nc = Math.max(0, cursor - 1);
inputs[nc].focus();
cursor = nc;
}
if (event.key === "ArrowRight") {
cursor = Math.min(4, cursor + 1);
inputs[cursor].focus();
const nc = Math.min(4, cursor + 1);
inputs[nc].focus();
cursor = nc;
}
if (event.key === " ") {
@@ -83,6 +86,9 @@
class:bg-green-600={colors[i] === Color.GREEN}
class:bg-yellow-600={colors[i] === Color.YELLOW}
class:bg-grey-600={colors[i] === Color.GREY}
onblur={() => {
cursor = -1;
}}
onbeforeinput={(event) => {
if (event.inputType === "insertText") {
event.preventDefault();
@@ -90,12 +96,14 @@
if (/^[a-zA-Z]$/.test(key)) {
letters[i] = key.toUpperCase();
if (cursor < 4) {
cursor++;
let nc = cursor;
if (nc < 4) {
nc++;
} else {
cursor = 0;
nc = 0;
}
inputs[cursor].focus();
inputs[nc].focus();
cursor = nc;
}
}
}}