mirror of
https://github.com/penpot/penpot.git
synced 2026-08-05 12:29:00 +00:00
🐛 Fix v2 text editor detaching typography tokens
This commit is contained in:
parent
5042a34e3c
commit
b66d1a657d
@ -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)))
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user