Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ function GhostEditor({ draft, target, locked }: { draft: string; target: string;
{typed.map((ch, index) => {
const ok = goal[index] === ch;
const shown = goal[index] ?? ch;
const missedSpace = shown === " " && !ok;
return (
<span
key={index}
data-typed={ok ? "ok" : "bad"}
className={ok ? undefined : "rounded-[2px] bg-error/12 text-error-foreground"}
className={cn(!ok && "rounded-[2px] bg-error/12 text-error-foreground", missedSpace && "relative")}
>
{shown === " " && !ok ? "·" : shown}
{shown}
{missedSpace ? (
<span aria-hidden className="pointer-events-none absolute inset-x-0 top-0 text-center [line-height:normal]">
·
</span>
) : null}
</span>
);
})}
Expand Down
18 changes: 17 additions & 1 deletion tests/play.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,23 @@ async function checkWrongKeysShowExpectedText(browser) {
const bad = spans.map((s, i) => (s.typed === "bad" ? i : -1)).filter((i) => i >= 0);
check(bad.join(",") === `2,${space}`, `wrong keys are marked at 2 and ${space} (got ${bad.join(",")})`);
check(spans[2]?.text === text[2], `a wrong letter shows the expected "${text[2]}" (got "${spans[2]?.text}")`);
check(spans[space]?.text === "\u00b7", `a key typed in place of a space shows a dot (got "${spans[space]?.text}")`);
check(spans[space]?.text.includes("\u00b7"), `a key typed in place of a space shows a dot (got "${spans[space]?.text}")`);
await page.addStyleTag({ content: '[data-testid="composer-editor"] { font-family: "Liberation Sans" !important; }' });
const ghostLeft = () =>
page.locator('[data-testid="composer-editor"] [data-ghost]').evaluate((el) => el.getClientRects()[0].left);
await page.keyboard.press("Backspace");
await page.keyboard.press("Backspace");
await page.keyboard.press("Backspace");
await page.keyboard.press("Backspace");
await page.keyboard.type(" ");
const leftAfterSpace = await ghostLeft();
await page.keyboard.press("Backspace");
await page.keyboard.type("x");
const leftAfterWrong = await ghostLeft();
check(
Math.abs(leftAfterSpace - leftAfterWrong) < 0.01,
`a wrong key on a space does not move the text after it (${leftAfterSpace} vs ${leftAfterWrong})`,
);
check(errors.length === 0, `no console errors in wrong key run${errors.length ? `: ${errors.join(" | ")}` : ""}`);
await page.close();
}
Expand Down
Loading