0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 07:11:32 -05:00

🐛 Fix paste ordering for frames not being respected

This commit is contained in:
alonso.torres 2022-03-23 15:11:55 +01:00
parent e8980fbbfe
commit 5a591d2acd
6 changed files with 37 additions and 31 deletions

View file

@ -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!)

View file

@ -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]))))

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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))))]