diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 5d1f0bc049..617539aef9 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -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)) diff --git a/frontend/test/frontend_tests/data/workspace_texts_test.cljs b/frontend/test/frontend_tests/data/workspace_texts_test.cljs index 57838bcd45..f677b01783 100644 --- a/frontend/test/frontend_tests/data/workspace_texts_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_texts_test.cljs @@ -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) ;; ---------------------------------------------------------------------------