From 65c6b7be7c95b253b5e47cefb5f67a1820eaa8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 21 May 2026 16:46:52 +0200 Subject: [PATCH] :bug: Fix changed font size when editing a text with no changes --- frontend/src/app/util/text/content/from_dom.cljs | 11 ++++++++++- frontend/src/app/util/text/content/to_dom.cljs | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/util/text/content/from_dom.cljs b/frontend/src/app/util/text/content/from_dom.cljs index dbc318cc08..da0fc394f2 100644 --- a/frontend/src/app/util/text/content/from_dom.cljs +++ b/frontend/src/app/util/text/content/from_dom.cljs @@ -8,6 +8,7 @@ (:require [app.common.data :as d] [app.common.types.text :as txt] + [app.util.dom :as dom] [app.util.text.content.styles :as styles])) (defn is-text-node @@ -60,7 +61,15 @@ (defn get-paragraph-styles [element] - (get-attrs-from-styles element (d/concat-set txt/paragraph-attrs txt/text-node-attrs) (d/merge txt/default-paragraph-attrs txt/default-text-attrs))) + (let [styles (get-attrs-from-styles element + (d/concat-set txt/paragraph-attrs txt/text-node-attrs) + (d/merge txt/default-paragraph-attrs txt/default-text-attrs)) + ;; Recover real font-size from data attribute, which to_dom/get-paragraph-styles may have + ;; changed to "0" ("0" trick to avoid it interfering with height calculation in the browser). + saved-font-size (dom/get-data element "saved-font-size")] + (cond-> styles + (some? saved-font-size) + (assoc :font-size saved-font-size)))) (defn get-root-styles [element] diff --git a/frontend/src/app/util/text/content/to_dom.cljs b/frontend/src/app/util/text/content/to_dom.cljs index 82ddf0fe32..50c48ebe30 100644 --- a/frontend/src/app/util/text/content/to_dom.cljs +++ b/frontend/src/app/util/text/content/to_dom.cljs @@ -133,7 +133,11 @@ (create-element "div" {:id (or (:key paragraph) (create-random-key)) - :data {:itype "paragraph"} + :data {:itype "paragraph" + ;; Save the real font size to be restored later in from-dom/get-paragraph-styles, + ;; because the function get-paragraph-styles here sets it to "0" in the css properties, + ;; to avoid the browser affecting the height calculation. + :saved-font-size (:font-size paragraph)} :style (get-paragraph-styles paragraph)} (mapv #(create-text-span % paragraph) (:children paragraph))))