mirror of
https://github.com/penpot/penpot.git
synced 2026-05-30 04:08:08 +00:00
🐛 Fix text styles sometimes being overidden when chaging shape text attrs
This commit is contained in:
parent
49d76d0f1c
commit
abc290582d
@ -36,6 +36,7 @@
|
|||||||
[app.main.fonts :as fonts]
|
[app.main.fonts :as fonts]
|
||||||
[app.main.router :as rt]
|
[app.main.router :as rt]
|
||||||
[app.render-wasm.api :as wasm.api]
|
[app.render-wasm.api :as wasm.api]
|
||||||
|
[app.render-wasm.text-editor :as wasm.text-editor]
|
||||||
[app.util.text-editor :as ted]
|
[app.util.text-editor :as ted]
|
||||||
[app.util.text.content.styles :as styles]
|
[app.util.text.content.styles :as styles]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
@ -465,13 +466,23 @@
|
|||||||
(when-not (some? (get-in state [:workspace-editor-state id]))
|
(when-not (some? (get-in state [:workspace-editor-state id]))
|
||||||
(let [objects (dsh/lookup-page-objects state)
|
(let [objects (dsh/lookup-page-objects state)
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
|
wasm? (features/active-feature? state "render-wasm/v1")
|
||||||
update-node? (fn [node]
|
update-node? (fn [node]
|
||||||
(or (txt/is-text-node? node)
|
(or (txt/is-text-node? node)
|
||||||
(txt/is-paragraph-node? node)))
|
(txt/is-paragraph-node? node)))
|
||||||
shape-ids (cond
|
shape-ids (cond
|
||||||
(cfh/text-shape? shape) [id]
|
(cfh/text-shape? shape) [id]
|
||||||
(cfh/group-shape? shape) (cfh/get-children-ids objects id))]
|
(cfh/group-shape? shape) (cfh/get-children-ids objects id))
|
||||||
(rx/of (dwsh/update-shapes shape-ids #(txt/update-text-content % update-node? d/txt-merge attrs))))))))
|
;; Keep WASM editor cache in sync with merged :content so a following
|
||||||
|
;; `apply-styles-to-selection` in `update-attrs` does not read stale
|
||||||
|
;; `shape-text-contents` and overwrite per-run fills (e.g. line-height).
|
||||||
|
merge-shape
|
||||||
|
(fn [sh]
|
||||||
|
(let [updated-shape (txt/update-text-content sh update-node? d/txt-merge attrs)]
|
||||||
|
(when wasm?
|
||||||
|
(wasm.text-editor/cache-shape-text-content! (:id updated-shape) (:content updated-shape)))
|
||||||
|
updated-shape))]
|
||||||
|
(rx/of (dwsh/update-shapes shape-ids merge-shape)))))))
|
||||||
|
|
||||||
(defn migrate-node
|
(defn migrate-node
|
||||||
[node]
|
[node]
|
||||||
@ -851,11 +862,13 @@
|
|||||||
(effect [_ state _]
|
(effect [_ state _]
|
||||||
(when (features/active-feature? state "text-editor/v2")
|
(when (features/active-feature? state "text-editor/v2")
|
||||||
(when-let [instance (:workspace-editor state)]
|
(when-let [instance (:workspace-editor state)]
|
||||||
(let [attrs-to-override (some-> (editor.v2/getCurrentStyle instance)
|
(when (seq attrs)
|
||||||
(styles/get-styles-from-style-declaration))
|
;; DOM `getCurrentStyle` reflects one resolved style (e.g. caret color). Merging
|
||||||
overriden-attrs (merge attrs-to-override attrs)
|
;; it with sidebar `attrs` and applying to the whole selection collapses mixed
|
||||||
styles (styles/attrs->styles overriden-attrs)]
|
;; fills/fonts when the user only changes one property (e.g. line-height).
|
||||||
(editor.v2/applyStylesToSelection instance styles)))))))
|
;; Apply only the explicit attributes from this action.
|
||||||
|
(let [styles (styles/attrs->styles attrs)]
|
||||||
|
(editor.v2/applyStylesToSelection instance styles))))))))
|
||||||
|
|
||||||
(defn update-all-attrs
|
(defn update-all-attrs
|
||||||
[ids attrs]
|
[ids attrs]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user