Compare commits

...
2 Commits
Author SHA1 Message Date
jonas 4ed16d404f chore(web): solver output error style 2026-08-22 22:36:46 +02:00
jonas ab7c9b5670 fix(web): cursor focusing 2026-08-22 22:36:34 +02:00
2 changed files with 19 additions and 11 deletions
+1 -1
View File
@@ -101,7 +101,7 @@
</table> </table>
</div> </div>
{:catch e} {:catch e}
<div class="rounded-lg border border-red-200 bg-red-50 p-4 text-red-700"> <div class="rounded-lg border border-red-400 bg-gray-800 p-4 text-red-400">
{e} {e}
</div> </div>
{/await} {/await}
+18 -10
View File
@@ -37,8 +37,9 @@
if (event.key === "Backspace") { if (event.key === "Backspace") {
if (letters[cursor] === "" && cursor > 0) { if (letters[cursor] === "" && cursor > 0) {
cursor--; const nc = cursor - 1;
inputs[cursor].focus(); inputs[nc].focus(); // Focusing / bluring resets cursor temporarily
cursor = nc;
} }
if (active) { if (active) {
@@ -47,13 +48,15 @@
} }
if (event.key === "ArrowLeft") { if (event.key === "ArrowLeft") {
cursor = Math.max(0, cursor - 1); const nc = Math.max(0, cursor - 1);
inputs[cursor].focus(); inputs[nc].focus();
cursor = nc;
} }
if (event.key === "ArrowRight") { if (event.key === "ArrowRight") {
cursor = Math.min(4, cursor + 1); const nc = Math.min(4, cursor + 1);
inputs[cursor].focus(); inputs[nc].focus();
cursor = nc;
} }
if (event.key === " ") { if (event.key === " ") {
@@ -83,6 +86,9 @@
class:bg-green-600={colors[i] === Color.GREEN} class:bg-green-600={colors[i] === Color.GREEN}
class:bg-yellow-600={colors[i] === Color.YELLOW} class:bg-yellow-600={colors[i] === Color.YELLOW}
class:bg-grey-600={colors[i] === Color.GREY} class:bg-grey-600={colors[i] === Color.GREY}
onblur={() => {
cursor = -1;
}}
onbeforeinput={(event) => { onbeforeinput={(event) => {
if (event.inputType === "insertText") { if (event.inputType === "insertText") {
event.preventDefault(); event.preventDefault();
@@ -90,12 +96,14 @@
if (/^[a-zA-Z]$/.test(key)) { if (/^[a-zA-Z]$/.test(key)) {
letters[i] = key.toUpperCase(); letters[i] = key.toUpperCase();
if (cursor < 4) { let nc = cursor;
cursor++; if (nc < 4) {
nc++;
} else { } else {
cursor = 0; nc = 0;
} }
inputs[cursor].focus(); inputs[nc].focus();
cursor = nc;
} }
} }
}} }}