mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 10:38:13 -05:00
Add basic shape duplicate functionality.
This commit is contained in:
parent
f8aaba6f31
commit
a312559b26
3 changed files with 35 additions and 24 deletions
|
@ -126,12 +126,8 @@
|
|||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [sid (random-uuid)
|
||||
pid (get-in state [:workspace :page])
|
||||
shape (merge shape {:id sid :page pid})]
|
||||
(as-> state $
|
||||
(update-in $ [:pages-by-id pid :shapes] conj sid)
|
||||
(assoc-in $ [:shapes-by-id sid] shape))))))
|
||||
(let [page (get-in state [:workspace :page])]
|
||||
(stsh/assoc-shape-to-page state shape page)))))
|
||||
|
||||
(defn delete-shape
|
||||
"Remove the shape using its id."
|
||||
|
@ -348,24 +344,6 @@
|
|||
(-apply-update [_ state]
|
||||
(assoc-in state [:workspace :selected] #{}))))
|
||||
|
||||
;; FIXME
|
||||
;; (defn copy-selected
|
||||
;; "Copy the selected shapes."
|
||||
;; []
|
||||
;; (letfn [(valid-selection? [shapes]
|
||||
;; (let [groups (into #{} (map :group shapes))]
|
||||
;; (= 1 (count groups))))]
|
||||
;; (reify
|
||||
;; rs/WatchEvent
|
||||
;; (-apply-watch [_ state]
|
||||
;; (let [selected (get-in state [:workspace :selected])
|
||||
;; selected (map #(get-in state [:shapes-by-id %]) selected)]
|
||||
;; (if (valid-selection? selected)
|
||||
;; (as-> selected $
|
||||
;; (map #(assoc % :id (random-uuid)) $)
|
||||
;; (map #(add-shape % %) $)
|
||||
;; (rx/from-coll $))))))
|
||||
|
||||
(defn group-selected
|
||||
[]
|
||||
(letfn [(update-shapes-on-page [state pid selected group]
|
||||
|
@ -405,6 +383,25 @@
|
|||
(update $ :workspace assoc :selected #{}))
|
||||
state))))))
|
||||
|
||||
(defn duplicate-selected
|
||||
[]
|
||||
(letfn [(all-toplevel? [coll]
|
||||
(every? #(nil? (:parent %)) coll))]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [selected (->> (get-in state [:workspace :selected])
|
||||
(mapv #(get-in state [:shapes-by-id %])))
|
||||
page (get-in state [:workspace :page])]
|
||||
(cond
|
||||
(all-toplevel? selected)
|
||||
(reduce #(stsh/assoc-shape-to-page %1 %2 page) state selected)
|
||||
|
||||
:else
|
||||
(do
|
||||
(println "Not implemented")
|
||||
state)))))))
|
||||
|
||||
(defn delete-selected
|
||||
"Deselect all and remove all selected shapes."
|
||||
[]
|
||||
|
|
|
@ -3,6 +3,19 @@
|
|||
(:require [uxbox.shapes :as sh]
|
||||
[uxbox.util.data :refer (index-of)]))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Shape Creation
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn assoc-shape-to-page
|
||||
[state shape page]
|
||||
(let [sid (random-uuid)
|
||||
shape (merge shape {:id sid :page page})]
|
||||
(as-> state $
|
||||
(update-in $ [:pages-by-id page :shapes] conj sid)
|
||||
(assoc-in $ [:shapes-by-id sid] shape))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Delete Shapes
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
:ctrl+shift+i #(rs/emit! (dw/toggle-flag :icons))
|
||||
:ctrl+shift+l #(rs/emit! (dw/toggle-flag :layers))
|
||||
:ctrl+r #(rs/emit! (dw/toggle-flag :ruler))
|
||||
:ctrl+d #(rs/emit! (dw/duplicate-selected))
|
||||
:esc #(rs/emit! (dw/deselect-all))
|
||||
:backspace #(rs/emit! (dw/delete-selected))
|
||||
:delete #(rs/emit! (dw/delete-selected))
|
||||
|
|
Loading…
Add table
Reference in a new issue