mirror of
https://github.com/penpot/penpot.git
synced 2025-03-12 07:41:43 -05:00
✨ Keeps position when paste in selected frame
This commit is contained in:
parent
d1437997d2
commit
104ce0967c
2 changed files with 17 additions and 7 deletions
|
@ -1282,6 +1282,13 @@
|
||||||
(rx/catch on-copy-error)
|
(rx/catch on-copy-error)
|
||||||
(rx/ignore)))))))
|
(rx/ignore)))))))
|
||||||
|
|
||||||
|
(defn selected-frame? [state]
|
||||||
|
(let [selected (get-in state [:workspace-local :selected])
|
||||||
|
page-id (:current-page-id state)
|
||||||
|
objects (dwc/lookup-page-objects state page-id)]
|
||||||
|
(and (and (= 1 (count selected))
|
||||||
|
(= :frame (get-in objects [(first selected) :type]))))))
|
||||||
|
|
||||||
(defn- paste-impl
|
(defn- paste-impl
|
||||||
[{:keys [selected objects] :as data}]
|
[{:keys [selected objects] :as data}]
|
||||||
(ptk/reify ::paste-impl
|
(ptk/reify ::paste-impl
|
||||||
|
@ -1293,14 +1300,17 @@
|
||||||
mouse-pos @ms/mouse-position
|
mouse-pos @ms/mouse-position
|
||||||
|
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
frame-id (-> (dwc/lookup-page-objects state page-id)
|
|
||||||
(cph/frame-id-by-position mouse-pos))
|
|
||||||
|
|
||||||
objects (d/mapm (fn [_ v] (assoc v
|
page-objects (dwc/lookup-page-objects state page-id)
|
||||||
:frame-id frame-id
|
page-selected (get-in state [:workspace-local :selected])
|
||||||
:parent-id frame-id)) objects)
|
|
||||||
|
|
||||||
delta (gpt/subtract mouse-pos orig-pos)
|
[frame-id delta] (if (selected-frame? state)
|
||||||
|
[(first page-selected)
|
||||||
|
(get page-objects (first page-selected))]
|
||||||
|
[(cph/frame-id-by-position page-objects mouse-pos)
|
||||||
|
(gpt/subtract mouse-pos orig-pos)])
|
||||||
|
|
||||||
|
objects (d/mapm (fn [_ v] (assoc v :frame-id frame-id :parent-id frame-id)) objects)
|
||||||
|
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
unames (-> (dwc/lookup-page-objects state page-id)
|
unames (-> (dwc/lookup-page-objects state page-id)
|
||||||
|
|
|
@ -272,7 +272,7 @@
|
||||||
|
|
||||||
(def ^:private change->name #(get-in % [:obj :name]))
|
(def ^:private change->name #(get-in % [:obj :name]))
|
||||||
|
|
||||||
(defn- prepare-duplicate-changes
|
(defn prepare-duplicate-changes
|
||||||
"Prepare objects to paste: generate new id, give them unique names,
|
"Prepare objects to paste: generate new id, give them unique names,
|
||||||
move to the position of mouse pointer, and find in what frame they
|
move to the position of mouse pointer, and find in what frame they
|
||||||
fit."
|
fit."
|
||||||
|
|
Loading…
Add table
Reference in a new issue