mirror of
https://github.com/penpot/penpot.git
synced 2025-05-14 08:46:39 +02:00
🐛 Fix box selection for components and nested frames
This commit is contained in:
parent
9e24ba7b39
commit
942f6167b0
4 changed files with 67 additions and 32 deletions
|
@ -59,7 +59,7 @@
|
||||||
(assoc-in state [:workspace-local :selrect] selrect))))
|
(assoc-in state [:workspace-local :selrect] selrect))))
|
||||||
|
|
||||||
(defn handle-area-selection
|
(defn handle-area-selection
|
||||||
[preserve? ignore-groups?]
|
[preserve?]
|
||||||
(ptk/reify ::handle-area-selection
|
(ptk/reify ::handle-area-selection
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -114,7 +114,20 @@
|
||||||
(rx/buffer-time 100)
|
(rx/buffer-time 100)
|
||||||
(rx/map last)
|
(rx/map last)
|
||||||
(rx/pipe (rxo/distinct-contiguous))
|
(rx/pipe (rxo/distinct-contiguous))
|
||||||
(rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?))))
|
(rx/with-latest-from ms/keyboard-mod ms/keyboard-shift)
|
||||||
|
(rx/map
|
||||||
|
(fn [[_ mod? shift?]]
|
||||||
|
(select-shapes-by-current-selrect shift? mod?))))
|
||||||
|
|
||||||
|
;; The last "tick" from the mouse cannot be buffered so we are sure
|
||||||
|
;; a selection is returned. Without this we can have empty selections on
|
||||||
|
;; very fast movement
|
||||||
|
(->> selrect-stream
|
||||||
|
(rx/last)
|
||||||
|
(rx/with-latest-from ms/keyboard-mod ms/keyboard-shift)
|
||||||
|
(rx/map
|
||||||
|
(fn [[_ mod? shift?]]
|
||||||
|
(select-shapes-by-current-selrect shift? mod? false)))))
|
||||||
|
|
||||||
(->> (rx/of (update-selrect nil))
|
(->> (rx/of (update-selrect nil))
|
||||||
;; We need the async so the current event finishes before updating the selrect
|
;; We need the async so the current event finishes before updating the selrect
|
||||||
|
@ -307,34 +320,39 @@
|
||||||
;; --- Select Shapes (By selrect)
|
;; --- Select Shapes (By selrect)
|
||||||
|
|
||||||
(defn select-shapes-by-current-selrect
|
(defn select-shapes-by-current-selrect
|
||||||
[preserve? ignore-groups?]
|
([preserve? ignore-groups?]
|
||||||
(ptk/reify ::select-shapes-by-current-selrect
|
(select-shapes-by-current-selrect preserve? ignore-groups? true))
|
||||||
ptk/WatchEvent
|
([preserve? ignore-groups? buffered?]
|
||||||
(watch [_ state _]
|
(ptk/reify ::select-shapes-by-current-selrect
|
||||||
(let [page-id (:current-page-id state)
|
ptk/WatchEvent
|
||||||
objects (wsh/lookup-page-objects state)
|
(watch [_ state _]
|
||||||
selected (wsh/lookup-selected state)
|
(let [page-id (:current-page-id state)
|
||||||
initial-set (if preserve?
|
objects (wsh/lookup-page-objects state)
|
||||||
selected
|
selected (wsh/lookup-selected state)
|
||||||
lks/empty-linked-set)
|
initial-set (if preserve?
|
||||||
selrect (dm/get-in state [:workspace-local :selrect])
|
selected
|
||||||
blocked? (fn [id] (dm/get-in objects [id :blocked] false))]
|
lks/empty-linked-set)
|
||||||
|
selrect (dm/get-in state [:workspace-local :selrect])
|
||||||
|
blocked? (fn [id] (dm/get-in objects [id :blocked] false))
|
||||||
|
|
||||||
(when selrect
|
ask-worker (if buffered? uw/ask-buffered! uw/ask!)]
|
||||||
(rx/empty)
|
|
||||||
(->> (uw/ask-buffered!
|
(if (some? selrect)
|
||||||
{:cmd :selection/query
|
(->> (ask-worker
|
||||||
:page-id page-id
|
{:cmd :selection/query
|
||||||
:rect selrect
|
:page-id page-id
|
||||||
:include-frames? true
|
:rect selrect
|
||||||
:ignore-groups? ignore-groups?
|
:include-frames? true
|
||||||
:full-frame? true
|
:ignore-groups? ignore-groups?
|
||||||
:using-selrect? true})
|
:full-frame? true
|
||||||
(rx/map #(cfh/clean-loops objects %))
|
:using-selrect? true})
|
||||||
(rx/map #(into initial-set (comp
|
(rx/filter some?)
|
||||||
(filter (complement blocked?))
|
(rx/map #(cfh/clean-loops objects %))
|
||||||
(remove (partial cfh/hidden-parent? objects))) %))
|
(rx/map #(into initial-set (comp
|
||||||
(rx/map select-shapes)))))))
|
(filter (complement blocked?))
|
||||||
|
(remove (partial cfh/hidden-parent? objects))) %))
|
||||||
|
(rx/map select-shapes))
|
||||||
|
(rx/empty)))))))
|
||||||
|
|
||||||
(defn select-inside-group
|
(defn select-inside-group
|
||||||
[group-id position]
|
[group-id position]
|
||||||
|
|
|
@ -112,6 +112,20 @@
|
||||||
(rx/sub! ob sub)
|
(rx/sub! ob sub)
|
||||||
sub))
|
sub))
|
||||||
|
|
||||||
|
(defonce keyboard-shift
|
||||||
|
(let [sub (rx/behavior-subject nil)
|
||||||
|
ob (->> keyboard
|
||||||
|
(rx/filter kbd/shift-key?)
|
||||||
|
(rx/map kbd/key-down-event?)
|
||||||
|
;; Fix a situation caused by using `ctrl+alt` kind of
|
||||||
|
;; shortcuts, that makes keyboard-alt stream
|
||||||
|
;; registering the key pressed but on blurring the
|
||||||
|
;; window (unfocus) the key down is never arrived.
|
||||||
|
(rx/merge window-blur)
|
||||||
|
(rx/pipe (rxo/distinct-contiguous)))]
|
||||||
|
(rx/sub! ob sub)
|
||||||
|
sub))
|
||||||
|
|
||||||
(defonce keyboard-meta
|
(defonce keyboard-meta
|
||||||
(let [sub (rx/behavior-subject nil)
|
(let [sub (rx/behavior-subject nil)
|
||||||
ob (->> keyboard
|
ob (->> keyboard
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
(st/emit! (dd/start-drawing drawing-tool)))
|
(st/emit! (dd/start-drawing drawing-tool)))
|
||||||
|
|
||||||
(or (not id) mod?)
|
(or (not id) mod?)
|
||||||
(st/emit! (dw/handle-area-selection shift? mod?))
|
(st/emit! (dw/handle-area-selection shift?))
|
||||||
|
|
||||||
(not drawing-tool)
|
(not drawing-tool)
|
||||||
(when-not workspace-read-only?
|
(when-not workspace-read-only?
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
match-criteria?
|
match-criteria?
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(and (not (:hidden shape))
|
(and (not (:hidden shape))
|
||||||
(or (= :frame (:type shape)) ;; We return frames even if blocked
|
(or (cfh/frame-shape? shape) ;; We return frames even if blocked
|
||||||
(not (:blocked shape)))
|
(not (:blocked shape)))
|
||||||
(or (not frame-id) (= frame-id (:frame-id shape)))
|
(or (not frame-id) (= frame-id (:frame-id shape)))
|
||||||
(case (:type shape)
|
(case (:type shape)
|
||||||
|
@ -135,8 +135,11 @@
|
||||||
(:bool :group) (not ignore-groups?)
|
(:bool :group) (not ignore-groups?)
|
||||||
true)
|
true)
|
||||||
|
|
||||||
|
;; This condition controls when to check for overlapping. Otherwise the
|
||||||
|
;; shape needs to be fully contained.
|
||||||
(or (not full-frame?)
|
(or (not full-frame?)
|
||||||
(not= :frame (:type shape))
|
(and (not ignore-groups?) (contains? shape :component-id))
|
||||||
|
(and (not ignore-groups?) (not (cfh/root-frame? shape)))
|
||||||
(and (d/not-empty? (:shapes shape))
|
(and (d/not-empty? (:shapes shape))
|
||||||
(gsh/rect-contains-shape? rect shape))
|
(gsh/rect-contains-shape? rect shape))
|
||||||
(and (empty? (:shapes shape))
|
(and (empty? (:shapes shape))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue