From 08d2dbc9bb3657dc3f823db7efb6387d548ab4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 28 Jun 2021 12:31:08 +0200 Subject: [PATCH] :sparkles: Preserve components on copy&paste when possible --- CHANGES.md | 14 +++++++------- frontend/src/app/main/data/workspace.cljs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 616273517..a19de1b6d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,13 +4,13 @@ ### :sparkles: New features -- Allow nested asset groups [Taiga #1716](https://tree.taiga.io/project/penpot/us/1716) -- Allow to ungroup assets [Taiga #1719](https://tree.taiga.io/project/penpot/us/1719) -- Allow to rename assets groups [Taiga #1721](https://tree.taiga.io/project/penpot/us/1721) -- Memorize collapse state of assets in panel [Taiga #1718](https://tree.taiga.io/project/penpot/us/1718) -- Headers button sets and menus review [Taiga #1663](https://tree.taiga.io/project/penpot/us/1663) -- Add the ability to offload file data to a cheaper storage when file - becomes inactive. +- Allow nested asset groups [Taiga #1716](https://tree.taiga.io/project/penpot/us/1716). +- Allow to ungroup assets [Taiga #1719](https://tree.taiga.io/project/penpot/us/1719). +- Allow to rename assets groups [Taiga #1721](https://tree.taiga.io/project/penpot/us/1721). +- Memorize collapse state of assets in panel [Taiga #1718](https://tree.taiga.io/project/penpot/us/1718). +- Headers button sets and menus review [Taiga #1663](https://tree.taiga.io/project/penpot/us/1663). +- Preserve components if possible, when pasted into a different file [Taiga #1063](https://tree.taiga.io/project/penpot/issue/1063). +- Add the ability to offload file data to a cheaper storage when file becomes inactive. ### :bug: Bugs fixed diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index aca9860a6..d131aa2a9 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1537,6 +1537,15 @@ (assoc change :index (get map-ids (:old-id change))) change))) + ;; Check if the shape is an instance whose master is defined in a + ;; library that is not linked to the current file + (foreign-instance? [shape objects state] + (let [root (cph/get-root-shape shape objects) + root-file-id (:component-file root)] + (and (some? root) + (not= root-file-id (:current-file-id state)) + (nil? (get-in state [:workspace-libraries root-file-id]))))) + ;; Procceed with the standard shape paste procediment. (do-paste [it state mouse-pos media] (let [media-idx (d/index-by :prev-id media) @@ -1551,8 +1560,8 @@ (assoc :parent-id parent-id) (cond-> - ;; Pasting from another file, we deattach components - (not= (:current-file-id state) (:file-id data)) + ;; if foreign instance, detach the shape + (foreign-instance? shape objects state) (dissoc :component-id :component-file :component-root?