mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
🎉 Copy and paste to cursor position
This commit is contained in:
parent
b1c029e16a
commit
83a02ad6e6
1 changed files with 23 additions and 15 deletions
|
@ -2051,43 +2051,51 @@
|
||||||
|
|
||||||
(defn- paste-impl
|
(defn- paste-impl
|
||||||
[{:keys [selected objects] :as data}]
|
[{:keys [selected objects] :as data}]
|
||||||
(letfn [(prepare-change [id]
|
(letfn [(prepare-change [delta id]
|
||||||
(let [obj (get objects id)]
|
(let [obj (get objects id)]
|
||||||
;; (prn "prepare-change" id obj)
|
|
||||||
(if (= :frame (:type obj))
|
(if (= :frame (:type obj))
|
||||||
(prepare-frame-change obj)
|
(prepare-frame-change obj delta)
|
||||||
(prepare-shape-change obj uuid/zero))))
|
(prepare-shape-change obj delta uuid/zero))))
|
||||||
|
|
||||||
(prepare-shape-change [obj frame-id]
|
(prepare-shape-change [obj delta frame-id]
|
||||||
(let [id (uuid/next)]
|
(let [id (uuid/next)
|
||||||
|
renamed-obj (assoc obj :id id :frame-id frame-id)
|
||||||
|
moved-obj (geom/move renamed-obj delta)]
|
||||||
{:type :add-obj
|
{:type :add-obj
|
||||||
:id id
|
:id id
|
||||||
:frame-id frame-id
|
:frame-id frame-id
|
||||||
:obj (assoc obj :id id :frame-id frame-id)}))
|
:obj moved-obj}))
|
||||||
|
|
||||||
(prepare-frame-change [obj]
|
(prepare-frame-change [obj delta]
|
||||||
(let [frame-id (uuid/next)
|
(let [frame-id (uuid/next)
|
||||||
sch (->> (map #(get objects %) (:shapes obj))
|
sch (->> (map #(get objects %) (:shapes obj))
|
||||||
(map #(prepare-shape-change % frame-id)))
|
(map #(prepare-shape-change % delta frame-id)))
|
||||||
|
renamed-frame (-> obj
|
||||||
|
(assoc :id frame-id)
|
||||||
|
(assoc :frame-id uuid/zero)
|
||||||
|
(assoc :shapes (mapv :id sch)))
|
||||||
|
moved-frame (geom/move renamed-frame delta)
|
||||||
fch {:type :add-obj
|
fch {:type :add-obj
|
||||||
:id frame-id
|
:id frame-id
|
||||||
:frame-id uuid/zero
|
:frame-id uuid/zero
|
||||||
:obj (-> obj
|
:obj moved-frame}]
|
||||||
(assoc :id frame-id)
|
|
||||||
(assoc :frame-id uuid/zero)
|
|
||||||
(assoc :shapes (mapv :id sch)))}]
|
|
||||||
(d/concat [fch] sch)))]
|
(d/concat [fch] sch)))]
|
||||||
|
|
||||||
(ptk/reify ::paste-impl
|
(ptk/reify ::paste-impl
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [rchanges (->> (map prepare-change selected)
|
(let [selected-objs (map #(get objects %) selected)
|
||||||
|
orig-pos (geom/selection-rect selected-objs)
|
||||||
|
mouse-pos @ms/mouse-position
|
||||||
|
delta {:x (- (:x mouse-pos) (:x orig-pos))
|
||||||
|
:y (- (:y mouse-pos) (:y orig-pos))}
|
||||||
|
|
||||||
|
rchanges (->> (map (partial prepare-change delta) selected)
|
||||||
(flatten))
|
(flatten))
|
||||||
uchanges (map (fn [ch]
|
uchanges (map (fn [ch]
|
||||||
{:type :del-obj
|
{:type :del-obj
|
||||||
:id (:id ch)})
|
:id (:id ch)})
|
||||||
rchanges)]
|
rchanges)]
|
||||||
(cljs.pprint/pprint rchanges)
|
|
||||||
(rx/of (commit-changes (vec rchanges)
|
(rx/of (commit-changes (vec rchanges)
|
||||||
(vec (reverse uchanges))
|
(vec (reverse uchanges))
|
||||||
{:commit-local? true})))))))
|
{:commit-local? true})))))))
|
||||||
|
|
Loading…
Reference in a new issue