From 144b4dc190ca5f65f35000f724610adaaafd1e9e Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 10 Jun 2026 23:51:57 +0530 Subject: [PATCH] fix: Stop mobile editor from reverting keystrokes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit currentText was $state, and the validated-state sync $effect both reads and writes it. Every keystroke (which sets currentText in the CodeMirror updateListener) therefore re-ran the effect while re-validation was still in flight, dispatching a full-document replacement with the stale validatedState text — visibly reverting the keystroke and resetting the cursor until validation caught up. The effect only needs to react to validatedState publishes, so make currentText a plain variable, matching DesktopEditor. No unit test: the repo has no component-test harness, and CodeMirror cannot mount under jsdom without one. Co-Authored-By: Claude Fable 5 --- src/lib/components/MobileEditor.svelte | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/components/MobileEditor.svelte b/src/lib/components/MobileEditor.svelte index 8523c39d..2308b32a 100644 --- a/src/lib/components/MobileEditor.svelte +++ b/src/lib/components/MobileEditor.svelte @@ -15,7 +15,10 @@ let editorView: EditorView | undefined; let editorContainer: HTMLDivElement; - let currentText = $state(''); + // Deliberately not $state: the sync effect below both reads and writes it, + // so a reactive currentText would make every keystroke re-run the effect + // against the not-yet-revalidated state and revert the user's input. + let currentText = ''; const themeCompartment = new Compartment(); const languageCompartment = new Compartment();