diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs index 1724072b61..18b5518886 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs @@ -77,6 +77,12 @@ (when (some? font-id) (fonts/ensure-loaded! font-id variant-id)))))) +(defn- strip-text-node-line-height + "Line-height is paragraph-level in the DOM; ignore it on text nodes when + checking whether the editor changed the shape content." + [content] + (txt/transform-nodes txt/is-text-node? #(dissoc % :line-height) content)) + (defn- initialize-event-handlers "Internal editor events handler initializer/destructor" [shape-id content editor-ref canvas-ref container-ref text-color] @@ -117,25 +123,29 @@ on-blur (fn [] (when-let [content (content/dom->cljs (dwt/get-editor-root instance))] - (let [state @st/state - objects (dsh/lookup-page-objects state) - shape (get objects shape-id) - current-name (:name shape) - generated-name (gen-name instance) - ;; Update name if: (1) it's a new shape (nil original content), or - ;; (2) the current name matches the generated name from original content - ;; (meaning it was never manually renamed) - update-name? (or (nil? original-content) - (and (some? current-name) - (some? original-content) - (= current-name (txt/generate-shape-name (txt/content->text original-content)))))] - (st/emit! (dwt/v2-update-text-shape-content shape-id content - :update-name? update-name? - :name generated-name - :finalize? true - ;; Single undo entry for the whole edit - :save-undo? true - :original-content original-content)))) + (when (or (nil? original-content) + (seq (txt/get-diff-attrs + (strip-text-node-line-height original-content) + (strip-text-node-line-height content)))) + (let [state @st/state + objects (dsh/lookup-page-objects state) + shape (get objects shape-id) + current-name (:name shape) + generated-name (gen-name instance) + ;; Update name if: (1) it's a new shape (nil original content), or + ;; (2) the current name matches the generated name from original content + ;; (meaning it was never manually renamed) + update-name? (or (nil? original-content) + (and (some? current-name) + (some? original-content) + (= current-name (txt/generate-shape-name (txt/content->text original-content)))))] + (st/emit! (dwt/v2-update-text-shape-content shape-id content + :update-name? update-name? + :name generated-name + :finalize? true + ;; Single undo entry for the whole edit + :save-undo? true + :original-content original-content))))) (let [container-node (mf/ref-val container-ref)] (dom/set-style! container-node "opacity" 0))) diff --git a/frontend/src/app/util/text/content/from_dom.cljs b/frontend/src/app/util/text/content/from_dom.cljs index 4d016313b5..87fb2c48e9 100644 --- a/frontend/src/app/util/text/content/from_dom.cljs +++ b/frontend/src/app/util/text/content/from_dom.cljs @@ -55,9 +55,12 @@ (assoc acc key (if (value-empty? value) (get defaults key) value)))) {} attrs))) +(def ^:private text-span-attrs + (vec (remove #{:line-height} txt/text-node-attrs))) + (defn get-text-span-styles [element] - (get-attrs-from-styles element txt/text-node-attrs (txt/get-default-text-attrs))) + (get-attrs-from-styles element text-span-attrs (txt/get-default-text-attrs))) (defn get-paragraph-styles [element] diff --git a/frontend/src/app/util/text/content/styles.cljs b/frontend/src/app/util/text/content/styles.cljs index 20a2454e1f..9220b0c0bf 100644 --- a/frontend/src/app/util/text/content/styles.cljs +++ b/frontend/src/app/util/text/content/styles.cljs @@ -6,6 +6,7 @@ (ns app.util.text.content.styles (:require + [app.common.data :as d] [app.common.transit :as transit] [app.common.types.text :as txt] [cuerdas.core :as str])) @@ -60,6 +61,12 @@ (= k :font-family) (str/unquote (str/replace v ", var(--fallback-families)" "")) + (and (= k :line-height) + (string? v) + (not= v "")) + (let [parsed (d/parse-double v)] + (if (number? parsed) parsed v)) + :else v))