0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 23:31:21 -05:00

🐛 Fix issue with shift+select to deselect shapes

This commit is contained in:
alonso.torres 2022-03-30 13:00:22 +02:00
parent 0392a1649f
commit 586bd13cc2
5 changed files with 56 additions and 37 deletions

View file

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## 1.12.3-beta
### :bug: Bugs fixed
- Fix issue with shift+select to deselect shapes [Taiga #3154](https://tree.taiga.io/project/penpot/issue/3154)
## 1.12.2-beta ## 1.12.2-beta
### :bug: Bugs fixed ### :bug: Bugs fixed

View file

@ -693,3 +693,13 @@
acc))) acc)))
acc)))))) acc))))))
(defn toggle-selection
([set value]
(toggle-selection set value false))
([set value toggle?]
(if-not toggle?
(conj (ordered-set) value)
(if (contains? set value)
(disj set value)
(conj set value)))))

View file

@ -117,13 +117,7 @@
(ptk/reify ::select-shape (ptk/reify ::select-shape
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(update-in state [:workspace-local :selected] (update-in state [:workspace-local :selected] d/toggle-selection id toggle?))
(fn [selected]
(if-not toggle?
(conj (d/ordered-set) id)
(if (contains? selected id)
(disj selected id)
(conj selected id))))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]

View file

@ -484,14 +484,23 @@
(defn start-move-selected (defn start-move-selected
"Enter mouse move mode, until mouse button is released." "Enter mouse move mode, until mouse button is released."
[] ([]
(start-move-selected nil false))
([id shift?]
(ptk/reify ::start-move-selected (ptk/reify ::start-move-selected
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [initial (deref ms/mouse-position) (let [initial (deref ms/mouse-position)
selected (wsh/lookup-selected state {:omit-blocked? true})
;; We toggle the selection so we don't have to wait for the event
selected
(cond-> (wsh/lookup-selected state {:omit-blocked? true})
(some? id)
(d/toggle-selection id shift?))
stopper (rx/filter ms/mouse-up? stream)] stopper (rx/filter ms/mouse-up? stream)]
(when-not (empty? selected) (when (or (d/not-empty? selected) (some? id))
(->> ms/mouse-position (->> ms/mouse-position
(rx/map #(gpt/to-vec initial %)) (rx/map #(gpt/to-vec initial %))
(rx/map #(gpt/length %)) (rx/map #(gpt/length %))
@ -500,14 +509,19 @@
(rx/with-latest vector ms/mouse-position-alt) (rx/with-latest vector ms/mouse-position-alt)
(rx/mapcat (rx/mapcat
(fn [[_ alt?]] (fn [[_ alt?]]
(rx/concat
(if (some? id)
(rx/of (dws/select-shape id shift?))
(rx/empty))
(if alt? (if alt?
;; When alt is down we start a duplicate+move ;; When alt is down we start a duplicate+move
(rx/of (start-move-duplicate initial) (rx/of (start-move-duplicate initial)
(dws/duplicate-selected false)) (dws/duplicate-selected false))
;; Otherwise just plain old move
(rx/of (start-move initial selected)))))
(rx/take-until stopper)))))))
;; Otherwise just plain old move
(rx/of (start-move initial selected))))))
(rx/take-until stopper))))))))
(defn- start-move-duplicate (defn- start-move-duplicate
[from-position] [from-position]

View file

@ -94,9 +94,7 @@
(st/emit! (dw/handle-area-selection shift? ctrl?)) (st/emit! (dw/handle-area-selection shift? ctrl?))
(not drawing-tool) (not drawing-tool)
(st/emit! (when (or shift? (not selected?)) (st/emit! (dw/start-move-selected id shift?)))))))))))
(dw/select-shape id shift?))
(dw/start-move-selected)))))))))))
(defn on-move-selected (defn on-move-selected
[hover hover-ids selected space?] [hover hover-ids selected space?]
@ -153,16 +151,13 @@
(let [ctrl? (kbd/ctrl? event) (let [ctrl? (kbd/ctrl? event)
shift? (kbd/shift? event) shift? (kbd/shift? event)
alt? (kbd/alt? event) alt? (kbd/alt? event)
hovering? (some? @hover) hovering? (some? @hover)
frame? (= :frame (:type @hover)) frame? (= :frame (:type @hover))]
selected? (contains? selected (:id @hover))]
(st/emit! (ms/->MouseEvent :click ctrl? shift? alt?)) (st/emit! (ms/->MouseEvent :click ctrl? shift? alt?))
(when (and hovering? (when (and hovering?
(or (not frame?) ctrl?) (or (not frame?) ctrl?)
(not @space?) (not @space?)
(not selected?)
(not edition) (not edition)
(not drawing-path?) (not drawing-path?)
(not drawing-tool)) (not drawing-tool))