From 06a1e0d70729cc2bc371fcf0d6c19978e6a046c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Sat, 22 Aug 2026 01:24:41 +0200 Subject: [PATCH] feat(web): use input types as cells --- web/src/App.svelte | 14 ++++++-- web/src/components/SolverOutput.svelte | 2 +- web/src/components/WordleLine.svelte | 46 ++++++++++++++++++-------- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/web/src/App.svelte b/web/src/App.svelte index 635875d..75a34d9 100644 --- a/web/src/App.svelte +++ b/web/src/App.svelte @@ -15,7 +15,7 @@ } from "./solver/types.ts"; import SolverOutput from "./components/SolverOutput.svelte"; import { FolderGit2 } from "@lucide/svelte"; - ("@lucide/svelte"); + import { tick } from "svelte"; let guesses = $state([ { @@ -41,6 +41,7 @@ let best_words: Promise | null = $state(null); let best_words_progress: EvaluateWordsProgress | null = $state(null); + let w_lines: WordleLine[] = []; let cursor = $state(0); async function reset() { @@ -72,8 +73,10 @@ } } - function handleKey(event: KeyboardEvent) { - if (event.key === "Enter" && event.shiftKey) { + async function handleKey(event: KeyboardEvent) { + if (/^[a-zA-Z ]$/.test(event.key)) { + w_lines[guesses.length - 1].focus(); + } else if (event.key === "Enter" && event.shiftKey) { best_words = solver_evaluate_words(5, (p) => { best_words_progress = p; }); @@ -105,6 +108,10 @@ Color.GREY, ], }); + + await tick(); + + w_lines[w_lines.length - 1].focus(); } } @@ -154,6 +161,7 @@ {#each guesses as g, i (g)} ; progress: EvaluateWordsProgress | null; - insert_guess: (word: string[]) => void | null; + insert_guess: ((word: string[]) => void) | null; } = $props(); function renderMath(txt: string | null) { diff --git a/web/src/components/WordleLine.svelte b/web/src/components/WordleLine.svelte index 8f746f6..28d43ec 100644 --- a/web/src/components/WordleLine.svelte +++ b/web/src/components/WordleLine.svelte @@ -15,19 +15,16 @@ info_gained = null, } = $props(); + let inputs: HTMLInputElement[] = []; + + export function focus() { + inputs[cursor].focus(); + } + function handleKey(event: KeyboardEvent) { if (!active) { return; } - if (/^[a-zA-Z]$/.test(event.key)) { - letters[cursor] = event.key.toUpperCase(); - - if (cursor < 4) { - cursor++; - } else { - cursor = 0; - } - } if (event.key === "Backspace") { if (letters[cursor] === "" && cursor > 0) { @@ -41,10 +38,12 @@ if (event.key === "ArrowLeft") { cursor = Math.max(0, cursor - 1); + inputs[cursor].focus(); } if (event.key === "ArrowRight") { cursor = Math.min(4, cursor + 1); + inputs[cursor].focus(); } if (event.key === " ") { @@ -57,18 +56,39 @@
{#each letters as letter, i} -
{ + if (event.inputType === "insertText") { + event.preventDefault(); + let key = event.data ?? ""; + + if (/^[a-zA-Z]$/.test(key)) { + letters[i] = key.toUpperCase(); + if (cursor < 4) { + cursor++; + } else { + cursor = 0; + } + inputs[cursor].focus(); + } + } + }} onclick={() => { if (!active) { return; @@ -79,9 +99,7 @@ cursor = i; } }} - > - {letter} -
+ /> {/each}