From 9f8d86a80e929e6ee2c8cbf0f611689f033339a2 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 30 Jan 2023 12:23:49 +0100 Subject: [PATCH] :bug: Fix copy paste texts with typography assets linked --- CHANGES.md | 1 + common/src/app/common/types/typography.cljc | 11 +++++++++++ frontend/src/app/main/data/workspace.cljs | 11 ++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b8e7d1d8d..2ec41e7de 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -67,6 +67,7 @@ - Fix paths not flagged as modified when resized [Taiga #4742](https://tree.taiga.io/project/penpot/issue/4742) - Fix resend invitation doesn't reset the expiration date [Taiga #4741](https://tree.taiga.io/project/penpot/issue/4741) - Fix incorrect state after undo page creation [Taiga #4690](https://tree.taiga.io/project/penpot/issue/4690) +- Fix copy paste texts with typography assets linked [Taiga #4750](https://tree.taiga.io/project/penpot/issue/4750) ### :heart: Community contributions by (Thank you!) diff --git a/common/src/app/common/types/typography.cljc b/common/src/app/common/types/typography.cljc index 426b00b7b..995552ffe 100644 --- a/common/src/app/common/types/typography.cljc +++ b/common/src/app/common/types/typography.cljc @@ -70,3 +70,14 @@ remap-typography content))))) +(defn remove-external-typographies + "Change the shape so that any use of an external typography now is removed" + [shape file-id] + (let [remove-ref-file #(dissoc % :typography-ref-file :typography-ref-id)] + + (update shape :content + (fn [content] + (txt/transform-nodes #(not= (:typography-ref-file %) file-id) + remove-ref-file + content))))) + diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index e6ece3a86..a57ec88d6 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -27,6 +27,7 @@ [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.shape.layout :as ctl] + [app.common.types.typography :as ctt] [app.common.uuid :as uuid] [app.config :as cf] [app.main.data.comments :as dcm] @@ -1550,7 +1551,8 @@ ;; Proceed with the standard shape paste process. (do-paste [it state mouse-pos media] - (let [page (wsh/lookup-page state) + (let [file-id (:current-file-id state) + page (wsh/lookup-page state) media-idx (d/index-by :prev-id media) ;; Calculate position for the pasted elements @@ -1565,7 +1567,10 @@ ;; if foreign instance, detach the shape (cond-> (foreign-instance? shape paste-objects state) (dissoc :component-id :component-file :component-root? - :remote-synced? :shape-ref :touched)))) + :remote-synced? :shape-ref :touched)) + ;; if is a text, remove references to external typographies + (cond-> (= (:type shape) :text) + (ctt/remove-external-typographies file-id)))) paste-objects (->> paste-objects (d/mapm process-shape)) @@ -1587,7 +1592,7 @@ (into (d/ordered-set))) undo-id (js/Symbol)] - (rx/of (dwu/start-undo-transaction undo-id) + (rx/of (dwu/start-undo-transaction undo-id) (dch/commit-changes changes) (dws/select-shapes selected) (ptk/data-event :layout/update [frame-id])