mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
✨ Simplify select all implementation
This commit is contained in:
parent
aceefc0485
commit
183e0bf985
1 changed files with 21 additions and 44 deletions
|
@ -178,56 +178,33 @@
|
||||||
(let [objects (wsh/lookup-page-objects state)]
|
(let [objects (wsh/lookup-page-objects state)]
|
||||||
(rx/of (dwc/expand-all-parents ids objects))))))
|
(rx/of (dwc/expand-all-parents ids objects))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn- select-siblings
|
|
||||||
[state parent]
|
|
||||||
(let [children (wsh/lookup-shapes state (:shapes parent))
|
|
||||||
selected (into (d/ordered-set)
|
|
||||||
(comp (remove :blocked) (map :id))
|
|
||||||
children)]
|
|
||||||
(rx/of (select-shapes selected))))
|
|
||||||
|
|
||||||
(defn- select-all-frame
|
|
||||||
[state]
|
|
||||||
(let [focus (:workspace-focus-selected state)
|
|
||||||
objects (-> (wsh/lookup-page-objects state)
|
|
||||||
(cp/focus-objects focus))
|
|
||||||
|
|
||||||
selected (let [frame-ids (into #{} (comp
|
|
||||||
(map (d/getf objects))
|
|
||||||
(map :frame-id))
|
|
||||||
(wsh/lookup-selected state))
|
|
||||||
frame-id (if (= 1 (count frame-ids))
|
|
||||||
(first frame-ids)
|
|
||||||
uuid/zero)]
|
|
||||||
(cph/get-immediate-children objects frame-id))
|
|
||||||
|
|
||||||
selected (into (d/ordered-set)
|
|
||||||
(comp (remove :blocked) (map :id))
|
|
||||||
selected)]
|
|
||||||
|
|
||||||
(rx/of (select-shapes selected))))
|
|
||||||
|
|
||||||
|
|
||||||
(defn select-all
|
(defn select-all
|
||||||
[]
|
[]
|
||||||
(ptk/reify ::select-all
|
(ptk/reify ::select-all
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [current-selection-parents (->> (wsh/lookup-selected state)
|
(let [;; Make the select-all aware of the focus mode; in this
|
||||||
(wsh/lookup-shapes state)
|
;; case delimit the objects to the focused shapes if focus
|
||||||
(into #{} (map :parent-id)))
|
;; mode is active
|
||||||
num-parents (count current-selection-parents)
|
focus (:workspace-focus-selected state)
|
||||||
parent (when (= num-parents 1)
|
objects (-> (wsh/lookup-page-objects state)
|
||||||
(wsh/lookup-shape state (first current-selection-parents)))]
|
(cp/focus-objects focus))
|
||||||
|
|
||||||
(case num-parents
|
lookup (d/getf objects)
|
||||||
0 (select-all-frame state)
|
parents (->> (wsh/lookup-selected state)
|
||||||
1 (if (cph/frame-shape? parent)
|
(into #{} (comp (keep lookup) (map :parent-id))))
|
||||||
(select-all-frame state)
|
|
||||||
(select-siblings state parent))
|
;; If we have a only unique parent, then use it as main
|
||||||
nil)))))
|
;; anchor for the selection; if not, use the root frame as
|
||||||
|
;; parent
|
||||||
|
parent (if (= 1 (count parents))
|
||||||
|
(-> parents first lookup)
|
||||||
|
(lookup uuid/zero))
|
||||||
|
|
||||||
|
toselect (->> (cph/get-immediate-children objects (:id parent))
|
||||||
|
(into (d/ordered-set) (comp (remove :blocked) (map :id))))]
|
||||||
|
|
||||||
|
(rx/of (select-shapes toselect))))))
|
||||||
|
|
||||||
(defn deselect-all
|
(defn deselect-all
|
||||||
"Clear all possible state of drawing, edition
|
"Clear all possible state of drawing, edition
|
||||||
|
|
Loading…
Add table
Reference in a new issue