mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
🐛 Drop nil style attrs when the legacy text editor saves (#13253)
The legacy editor writes the attrs it gets into the data of an empty paragraph, nil values included, so turning off a text decoration there leaves :text-decoration nil. finalize-editor-state copied that data into the shape content as it was, the only commit path that skipped ensure-valid-text-content, and the backend rejected the shape. Build the content with a helper that runs it, shared by both renderer branches. Closes #13252 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
aa5e62a417
commit
915d405a9c
@ -300,6 +300,16 @@
|
||||
(update :workspace-editor-state dissoc id)
|
||||
(update :workspace-new-text-shapes disj id))))))
|
||||
|
||||
(defn editor-shape-content
|
||||
"The `:content` of the text `shape` after editing it with the legacy
|
||||
editor: the `exported` editor content with the root attrs of the
|
||||
shape. The editor keeps paragraph data as it was set, nil values
|
||||
included, so the result goes through `ensure-valid-text-content` like
|
||||
the other commit paths."
|
||||
[exported shape]
|
||||
(ensure-valid-text-content
|
||||
(d/merge exported (dissoc (:content shape) :children))))
|
||||
|
||||
(defn finalize-editor-state
|
||||
[id update-name?]
|
||||
(ptk/reify ::finalize-editor-state
|
||||
@ -316,8 +326,7 @@
|
||||
new-shape? (contains? (:workspace-new-text-shapes state) id)]
|
||||
(if (ted/content-has-text? content)
|
||||
(if (features/active-feature? state "render-wasm/v1")
|
||||
(let [content (d/merge (ted/export-content content)
|
||||
(dissoc (:content shape) :children))
|
||||
(let [content (editor-shape-content (ted/export-content content) shape)
|
||||
new-size (dwwt/get-wasm-text-new-size shape content)]
|
||||
(rx/merge
|
||||
(rx/of (update-editor-state shape nil))
|
||||
@ -337,8 +346,7 @@
|
||||
(ctm/change-size shape (:width new-size) (:height new-size))))))
|
||||
{:undo-group (when new-shape? id)})))))
|
||||
|
||||
(let [content (d/merge (ted/export-content content)
|
||||
(dissoc (:content shape) :children))
|
||||
(let [content (editor-shape-content (ted/export-content content) shape)
|
||||
modifiers (get-in state [:workspace-text-modifier id])]
|
||||
(rx/merge
|
||||
(rx/of (update-editor-state shape nil))
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape.text :as ctst]
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
@ -642,6 +643,29 @@
|
||||
(let [node {:type "paragraph" :children []}]
|
||||
(t/is (= node (dwt/ensure-valid-text-content node))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Tests: editor-shape-content (legacy editor commit)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(t/deftest editor-shape-content-drops-nil-paragraph-attrs
|
||||
(t/testing "a nil :text-decoration left in the paragraph data is dropped"
|
||||
(let [exported {:type "root"
|
||||
:children [{:type "paragraph-set"
|
||||
:children [{:type "paragraph"
|
||||
:key "1gt0a"
|
||||
:font-family "sourcesanspro"
|
||||
:text-decoration nil
|
||||
:typography-ref-id nil
|
||||
:children [{:text "hello"
|
||||
:font-family "sourcesanspro"}]}]}]}
|
||||
shape {:content {:type "root" :vertical-align "center" :children []}}
|
||||
content (dwt/editor-shape-content exported shape)
|
||||
para (get-in content [:children 0 :children 0])]
|
||||
(t/is (ctst/valid-content? content))
|
||||
(t/is (not (contains? para :text-decoration)))
|
||||
(t/is (= "sourcesanspro" (:font-family para)))
|
||||
(t/is (= "center" (:vertical-align content))))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Tests: merge-live-text-dimensions (Design tab / edition outline)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user