mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
🎉 Calculate in which frame the pasted objects fit
This commit is contained in:
parent
82c264b75f
commit
a4d8675a15
1 changed files with 17 additions and 14 deletions
|
@ -973,9 +973,8 @@
|
||||||
:fill-opacity 1})
|
:fill-opacity 1})
|
||||||
|
|
||||||
(defn- calculate-frame-overlap
|
(defn- calculate-frame-overlap
|
||||||
[data shape]
|
[objects shape]
|
||||||
(let [objects (:objects data)
|
(let [rshp (geom/shape->rect-shape shape)
|
||||||
rshp (geom/shape->rect-shape shape)
|
|
||||||
|
|
||||||
xfmt (comp
|
xfmt (comp
|
||||||
(filter #(= :frame (:type %)))
|
(filter #(= :frame (:type %)))
|
||||||
|
@ -997,10 +996,10 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [page-id (::page-id state)
|
(let [page-id (::page-id state)
|
||||||
data (get-in state [:workspace-data page-id])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
shape (-> (geom/setup-proportions attrs)
|
shape (-> (geom/setup-proportions attrs)
|
||||||
(assoc :id id))
|
(assoc :id id))
|
||||||
frame-id (calculate-frame-overlap data shape)
|
frame-id (calculate-frame-overlap objects shape)
|
||||||
shape (merge shape-default-attrs shape {:frame-id frame-id})]
|
shape (merge shape-default-attrs shape {:frame-id frame-id})]
|
||||||
(impl-assoc-shape state shape)))
|
(impl-assoc-shape state shape)))
|
||||||
|
|
||||||
|
@ -1524,9 +1523,9 @@
|
||||||
(if (nil? id)
|
(if (nil? id)
|
||||||
[rch uch]
|
[rch uch]
|
||||||
(let [pid (::page-id state)
|
(let [pid (::page-id state)
|
||||||
dta (get-in state [:workspace-data pid])
|
objects (get-in state [:workspace-data pid :objects])
|
||||||
obj (get-in dta [:objects id])
|
obj (get objects id)
|
||||||
fid (calculate-frame-overlap dta obj)]
|
fid (calculate-frame-overlap objects obj)]
|
||||||
(if (not= fid (:frame-id obj))
|
(if (not= fid (:frame-id obj))
|
||||||
(recur (first ids)
|
(recur (first ids)
|
||||||
(rest ids)
|
(rest ids)
|
||||||
|
@ -2060,8 +2059,8 @@
|
||||||
(defn- paste-impl
|
(defn- paste-impl
|
||||||
[{:keys [selected objects] :as data}]
|
[{:keys [selected objects] :as data}]
|
||||||
(letfn [(prepare-changes [state delta]
|
(letfn [(prepare-changes [state delta]
|
||||||
"Prepare objects to paste: generate new id, give them unique names,
|
"Prepare objects to paste: generate new id, give them unique names, move
|
||||||
and move to the position of mouse pointer"
|
to the position of mouse pointer, and find in what frame they fit."
|
||||||
(let [page-id (::page-id state)]
|
(let [page-id (::page-id state)]
|
||||||
(loop [existing-objs (get-in state [:workspace-data page-id :objects])
|
(loop [existing-objs (get-in state [:workspace-data page-id :objects])
|
||||||
chgs []
|
chgs []
|
||||||
|
@ -2081,17 +2080,21 @@
|
||||||
(let [obj (get objects id)]
|
(let [obj (get objects id)]
|
||||||
(if (= :frame (:type obj))
|
(if (= :frame (:type obj))
|
||||||
(prepare-frame-change existing-objs obj delta)
|
(prepare-frame-change existing-objs obj delta)
|
||||||
(prepare-shape-change existing-objs obj delta uuid/zero))))
|
(prepare-shape-change existing-objs obj delta nil))))
|
||||||
|
|
||||||
(prepare-shape-change [objects obj delta frame-id]
|
(prepare-shape-change [objects obj delta frame-id]
|
||||||
(let [id (uuid/next)
|
(let [id (uuid/next)
|
||||||
name (impl-generate-unique-name objects (:name obj))
|
name (impl-generate-unique-name objects (:name obj))
|
||||||
renamed-obj (assoc obj :id id :frame-id frame-id :name name)
|
renamed-obj (assoc obj :id id :name name)
|
||||||
moved-obj (geom/move renamed-obj delta)]
|
moved-obj (geom/move renamed-obj delta)
|
||||||
|
frame-id (if frame-id
|
||||||
|
frame-id
|
||||||
|
(calculate-frame-overlap objects moved-obj))
|
||||||
|
reframed-obj (assoc moved-obj :frame-id frame-id)]
|
||||||
{:type :add-obj
|
{:type :add-obj
|
||||||
:id id
|
:id id
|
||||||
:frame-id frame-id
|
:frame-id frame-id
|
||||||
:obj moved-obj}))
|
:obj reframed-obj}))
|
||||||
|
|
||||||
(prepare-frame-change [objects obj delta]
|
(prepare-frame-change [objects obj delta]
|
||||||
(let [frame-id (uuid/next)
|
(let [frame-id (uuid/next)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue