From 59982c9056bc3d7f30d875a57c6dcd8a9c4e20a5 Mon Sep 17 00:00:00 2001 From: Elena Torro Date: Fri, 9 May 2025 11:23:00 +0200 Subject: [PATCH] :bug: Fix parsing text spaces --- frontend/src/app/render_wasm/api/texts.cljs | 6 ++---- render-wasm/src/shapes/text.rs | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/render_wasm/api/texts.cljs b/frontend/src/app/render_wasm/api/texts.cljs index a70d5019b..e48cec362 100644 --- a/frontend/src/app/render_wasm/api/texts.cljs +++ b/frontend/src/app/render_wasm/api/texts.cljs @@ -10,8 +10,7 @@ [app.render-wasm.helpers :as h] [app.render-wasm.mem :as mem] [app.render-wasm.serializers :as sr] - [app.render-wasm.wasm :as wasm] - [clojure.string :as str])) + [app.render-wasm.wasm :as wasm])) (defn utf8->buffer [text] (let [encoder (js/TextEncoder.)] @@ -21,8 +20,7 @@ ;; buffer has the following format: ;; [ ] [leaves paragraph text] - (let [leaves (filter #(not (str/blank? (:text %))) leaves) - num-leaves (count leaves) + (let [num-leaves (count leaves) paragraph-attr-size 48 leaf-attr-size 52 metadata-size (+ 1 paragraph-attr-size (* num-leaves leaf-attr-size)) diff --git a/render-wasm/src/shapes/text.rs b/render-wasm/src/shapes/text.rs index d3455619a..067684175 100644 --- a/render-wasm/src/shapes/text.rs +++ b/render-wasm/src/shapes/text.rs @@ -451,8 +451,11 @@ impl RawTextData { } let text_utf8 = buffer[offset..text_end].to_vec(); - let text = String::from_utf8(text_utf8).expect("Invalid UTF-8 text"); + if text_utf8.is_empty() { + return (String::new(), text_end); + } + let text = String::from_utf8_lossy(&text_utf8).to_string(); (text, text_end) } }