From b9756bc8571cd4c97e9f9e77f5bc137690d00f9c Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 26 Nov 2026 16:29:46 +0100 Subject: [PATCH] :bug: Apply a font size set at the caret to text typed with an IME Text typed with an IME took the style of the character before it, not the size or other style just chosen at the caret, though the sidebar kept showing the chosen one. Composition start dropped the pending caret style. The caret position is now kept at composition start, and the commit gives the composed text the pending style, as plain typing does. Nothing touches the store or the composing element until the composition ends. AI-assisted-by: claude-opus-5-5 --- .../ui/workspace/shapes/text/v3_editor.cljs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs index 90d22ba9b2..f579748d86 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs @@ -389,6 +389,10 @@ composition-base-ref (mf/use-ref 0) composition-text-ref (mf/use-ref "") + ;; Where the composition started, when a pending caret style waits for + ;; its text; nil otherwise. The commit gives that text the style. + composition-start-ref (mf/use-ref nil) + ;; IME cursor offset last read from the DOM selection; nil after a text change. synced-offset-ref (mf/use-ref nil) @@ -526,8 +530,13 @@ (let [node (mf/ref-val contenteditable-ref)] (or (text-before-selection node) (count (.-textContent node))))) - ;; IME composition supplies its own text; drop any pending caret style. - (text-editor/clear-pending-caret-styles!) + ;; Keep a pending caret style for the committed text, as plain + ;; typing does. Reading the WASM selection leaves the DOM and the + ;; store alone, so the IME is not disturbed. + (mf/set-ref-val! composition-start-ref + (let [shape-id (text-editor/text-editor-get-active-shape-id)] + (when (some? (text-editor/get-pending-caret-styles shape-id)) + (text-editor/selection-start)))) (text-editor/text-editor-composition-start))) on-composition-update @@ -566,9 +575,15 @@ (mf/use-fn (fn [^js event] (mf/set-ref-val! composing-ref false) - (let [data (or (.-data event) "")] + (let [data (or (.-data event) "") + before (mf/ref-val composition-start-ref)] + (mf/set-ref-val! composition-start-ref nil) (wasm.api/finish-text-editor-composition data) - (sync-wasm-text-editor-content!) + ;; Store and DOM writes are safe again: the composition is over. + (if (and (some? before) (seq data)) + (sync-with-pending-caret-styles! + (text-editor/text-editor-get-active-shape-id) before) + (sync-wasm-text-editor-content!)) (wasm.api/request-render-preserving-target "text-composition")) (reset-input-node (mf/ref-val contenteditable-ref)) ;; Move the surface onto the caret, now past the committed text.