diff --git a/CHANGES.md b/CHANGES.md index 0af1b2b89..3f4195984 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -60,6 +60,7 @@ - Fix clickable area in layers [#1680](https://github.com/penpot/penpot/issues/1680) - Fix problems with trackpad zoom and scroll in MacOS [#1161](https://github.com/penpot/penpot/issues/1161) - Fix problem with copy/paste in Safari [#1209](https://github.com/penpot/penpot/issues/1209) +- Fix paste ordering for frames not being respected [Taiga #3097](https://tree.taiga.io/project/penpot/issue/3097) ### :arrow_up: Deps updates ### :heart: Community contributions by (Thank you!) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index e950bc7cc..242f5b9e3 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -81,9 +81,7 @@ shapes (nil? index) - (if (= :frame (:type obj)) - (into [id] shapes) - (conj shapes id)) + (conj shapes id) :else (cph/insert-at-index shapes index [id])))) diff --git a/common/src/app/common/pages/changes_builder.cljc b/common/src/app/common/pages/changes_builder.cljc index b0cf90e84..e30f19dcd 100644 --- a/common/src/app/common/pages/changes_builder.cljc +++ b/common/src/app/common/pages/changes_builder.cljc @@ -198,8 +198,7 @@ (assert-page-id changes) (let [obj (cond-> obj (not= index ::undefined) - (assoc :index index)) - + (assoc ::index index)) add-change {:type :add-obj :id (:id obj) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index ba6d274d3..25de91e04 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1437,7 +1437,7 @@ (calculate-paste-position [state mouse-pos in-viewport?] (let [page-objects (wsh/lookup-page-objects state) selected-objs (map #(get paste-objects %) selected) - has-frame? (d/seek #(= (:type %) :frame) selected-objs) + has-frame? (d/seek #(= (:type %) :frame) selected-objs) page-selected (wsh/lookup-selected state) wrapper (gsh/selection-rect selected-objs) orig-pos (gpt/point (:x1 wrapper) (:y1 wrapper))] @@ -1524,21 +1524,18 @@ ;; Calculate position for the pasted elements [frame-id parent-id delta index] (calculate-paste-position state mouse-pos in-viewport?) - paste-objects (->> paste-objects - (d/mapm (fn [_ shape] - (-> shape - (assoc :frame-id frame-id) - (assoc :parent-id parent-id) + process-shape + (fn [_ shape] + (-> shape + (assoc :frame-id frame-id) + (assoc :parent-id parent-id) - (cond-> - ;; if foreign instance, detach the shape - (foreign-instance? shape paste-objects state) - (dissoc :component-id - :component-file - :component-root? - :remote-synced? - :shape-ref - :touched)))))) + ;; 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)))) + + paste-objects (->> paste-objects (d/mapm process-shape)) all-objects (merge (:objects page) paste-objects) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 98d6dc0c3..dfeb3a043 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -325,7 +325,7 @@ selected) changes (-> (pcb/empty-changes it page-id) - (pcb/add-object shape))] + (pcb/add-object shape {:index (when (= :frame (:type shape)) 0)}))] (rx/concat (rx/of (dch/commit-changes changes) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index fa02d1390..762397938 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -284,15 +284,27 @@ (let [shapes (map (d/getf all-objects) ids) unames (volatile! (dwc/retrieve-used-names (:objects page))) update-unames! (fn [new-name] (vswap! unames conj new-name)) - all-ids (reduce #(into %1 (cons %2 (cph/get-children-ids all-objects %2))) #{} ids) - ids-map (into {} (map #(vector % (uuid/next))) all-ids)] - (-> (reduce (fn [changes shape] - (prepare-duplicate-change changes all-objects page unames update-unames! ids-map shape delta)) - (-> (pcb/empty-changes it) - (pcb/with-page page) - (pcb/with-objects all-objects)) - shapes) - (prepare-duplicate-flows shapes page ids-map)))) + all-ids (reduce #(into %1 (cons %2 (cph/get-children-ids all-objects %2))) (d/ordered-set) ids) + ids-map (into {} (map #(vector % (uuid/next))) all-ids) + + init-changes + (-> (pcb/empty-changes it) + (pcb/with-page page) + (pcb/with-objects all-objects)) + + changes + (->> shapes + (reduce #(prepare-duplicate-change %1 + all-objects + page + unames + update-unames! + ids-map + %2 + delta) + init-changes))] + + (prepare-duplicate-flows changes shapes page ids-map))) (defn- prepare-duplicate-change [changes objects page unames update-unames! ids-map shape delta] @@ -349,7 +361,6 @@ (geom/move delta) (d/update-when :interactions #(cti/remap-interactions % ids-map objects))) - changes (pcb/add-object changes new-obj {:ignore-touched true}) changes (-> (pcb/add-object changes new-obj {:ignore-touched true}) (pcb/amend-last-change #(assoc % :old-id (:id obj))))]