mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-12 09:13:23 +00:00
Audit of the previous commit found three problems in it. The `ime.refocus` sent on every tap carried the field's full editing state, so a tap in a long textarea put 40KB on the wire per tap (145B before), and its geometry made the page mirror the whole field into a hidden div and force a synchronous layout — measured at ~3.5ms per tap on a 40k-char textarea, doubling the cost of every tap in a field. Split the message in two: taps ring a payload-free `ime.wantkb` doorbell, and the host answers it with the `ime.resync` it already had — but only when it no longer mirrors the field, so the common "keyboard was dismissed, tap to get it back" case is one small message and no round trip. Per-tap payload is now constant (~180B) and the per-tap CPU cost is back at parity with before the fix. The "am I already hosting this field" check read `hasFocus()` alone, so a focus that lingers past `clearFocus()` (a lone focusable in the hierarchy can take it straight back) would have skipped the re-seed and shipped the previous tab's text to the page on the first keystroke. Track mirroring explicitly. The keyboard-restore mark was armed by any keyboard up at tab-switch time, including one belonging to the browser's own address bar; require that the mirror actually holds it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AC3ambee9KFcvHCS6HRqhS