mirror of
https://github.com/penpot/penpot.git
synced 2025-03-28 15:41:25 -05:00
Deselect all auto removed groups in drag & drop operations.
This fixes strange corner case that causes enabling the grouping button when no visible shape is selected.
This commit is contained in:
parent
cc0b61f122
commit
57e98487e1
3 changed files with 111 additions and 97 deletions
|
@ -154,7 +154,8 @@
|
|||
[state {:keys [group] :as shape}]
|
||||
(if-let [group' (get-in state [:shapes group])]
|
||||
(if (empty? (:items group'))
|
||||
(dissoc-shape state group')
|
||||
(-> (dissoc-shape state group')
|
||||
(update-in [:workspace :selected] disj (:id group')))
|
||||
state)
|
||||
state))
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@
|
|||
:path i/curve
|
||||
:rect i/box
|
||||
:text i/text
|
||||
:group i/folder))
|
||||
:group i/folder
|
||||
nil))
|
||||
|
||||
;; --- Shape Name (Component)
|
||||
|
||||
|
|
|
@ -105,12 +105,16 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; drop shape: move shape before other shape
|
||||
|
||||
(t/deftest drop-shape-test1
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 2 3]}}
|
||||
:shapes {1 {:id 1 :page 1}
|
||||
2 {:id 2 :page 1}
|
||||
3 {:id 3 :page 1}}}
|
||||
expected (assoc-in initial [:pages 1 :shapes] [3 1 2])
|
||||
expected {:pages {1 {:id 1, :shapes [3 1 2]}},
|
||||
:shapes {1 {:id 1, :page 1},
|
||||
2 {:id 2, :page 1},
|
||||
3 {:id 3, :page 1}}}
|
||||
result (impl/drop-shape initial 3 1 :before)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
|
@ -118,12 +122,17 @@
|
|||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move shape after other shape
|
||||
|
||||
(t/deftest drop-shape-test2
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 2 3]}}
|
||||
:shapes {1 {:id 1 :page 1}
|
||||
2 {:id 2 :page 1}
|
||||
3 {:id 3 :page 1}}}
|
||||
expected (assoc-in initial [:pages 1 :shapes] [1 3 2])
|
||||
2 {:id 2 :page 1}
|
||||
3 {:id 3 :page 1}}}
|
||||
|
||||
expected {:pages {1 {:id 1, :shapes [1 3 2]}},
|
||||
:shapes {1 {:id 1, :page 1},
|
||||
2 {:id 2, :page 1},
|
||||
3 {:id 3, :page 1}}}
|
||||
result (impl/drop-shape initial 3 1 :after)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
|
@ -131,35 +140,39 @@
|
|||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move shape before other shape that is part of group.
|
||||
|
||||
(t/deftest drop-shape-test3
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 3 4]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2]}
|
||||
2 {:id 2 :page 1 :group 1}
|
||||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [1 4])
|
||||
(assoc-in [:shapes 1 :items] [3 2])
|
||||
(assoc-in [:shapes 3 :group] 1))
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [2]}
|
||||
2 {:id 2 :page 1 :group 1}
|
||||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
|
||||
expected {:pages {1 {:id 1, :shapes [1 4]}},
|
||||
:shapes {1 {:id 1, :page 1, :type :group, :items [3 2]},
|
||||
2 {:id 2, :page 1, :group 1},
|
||||
3 {:id 3, :page 1, :group 1},
|
||||
4 {:id 4, :page 1}}}
|
||||
|
||||
result (impl/drop-shape initial 3 2 :before)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
(t/is (= result expected))
|
||||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move shape inside group
|
||||
|
||||
(t/deftest drop-shape-test4
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 3 4]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2]}
|
||||
2 {:id 2 :page 1 :group 1}
|
||||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [1 4])
|
||||
(assoc-in [:shapes 1 :items] [2 3])
|
||||
(assoc-in [:shapes 3 :group] 1))
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [2]}
|
||||
2 {:id 2 :page 1 :group 1}
|
||||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
expected {:pages {1 {:id 1, :shapes [1 4]}},
|
||||
:shapes {1 {:id 1, :page 1, :type :group, :items [2 3]},
|
||||
2 {:id 2, :page 1, :group 1},
|
||||
3 {:id 3, :page 1, :group 1},
|
||||
4 {:id 4, :page 1}}}
|
||||
result (impl/drop-shape initial 3 1 :inside)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
|
@ -167,37 +180,36 @@
|
|||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move shape outside of group
|
||||
|
||||
(t/deftest drop-shape-test5
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 4]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2 3]}
|
||||
2 {:id 2 :page 1 :group 1}
|
||||
3 {:id 3 :page 1 :group 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [1 4 3])
|
||||
(assoc-in [:shapes 1 :items] [2])
|
||||
(update-in [:shapes 3] dissoc :group))
|
||||
result (impl/drop-shape initial 3 4 :after)]
|
||||
(let [initial {:workspace {:selected #{1}}
|
||||
:pages {1 {:id 1 :shapes [1 3]}}
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [2]}
|
||||
2 {:id 2 :page 1 :group 1}
|
||||
3 {:id 3 :page 1}}}
|
||||
expected {:workspace {:selected #{}}
|
||||
:pages {1 {:id 1, :shapes [3 2]}},
|
||||
:shapes {2 {:id 2, :page 1},
|
||||
3 {:id 3, :page 1}}}
|
||||
result (impl/drop-shape initial 2 3 :after)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
(t/is (= result expected))
|
||||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move group inside group
|
||||
|
||||
(t/deftest drop-shape-test6
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 2]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [3]}
|
||||
2 {:id 2 :page 1
|
||||
:type :group
|
||||
:items [4]}
|
||||
3 {:id 3 :page 1 :group 1}
|
||||
4 {:id 4 :page 1 :group 2}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [1])
|
||||
(assoc-in [:shapes 1 :items] [3 2])
|
||||
(assoc-in [:shapes 2 :group] 1))
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [3]}
|
||||
2 {:id 2 :page 1 :type :group :items [4]}
|
||||
3 {:id 3 :page 1 :group 1}
|
||||
4 {:id 4 :page 1 :group 2}}}
|
||||
expected {:pages {1 {:id 1, :shapes [1]}},
|
||||
:shapes {1 {:id 1, :page 1, :type :group, :items [3 2]},
|
||||
2 {:id 2, :page 1, :type :group, :items [4], :group 1},
|
||||
3 {:id 3, :page 1, :group 1},
|
||||
4 {:id 4, :page 1, :group 2}}}
|
||||
result (impl/drop-shape initial 2 3 :after)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
|
@ -205,21 +217,20 @@
|
|||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move group outside group
|
||||
|
||||
(t/deftest drop-shape-test7
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 3]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2]}
|
||||
2 {:id 2 :page 1
|
||||
:group 1
|
||||
:type :group
|
||||
:items [4]}
|
||||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1 :group 2}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [2 3])
|
||||
(update-in [:shapes] dissoc 1)
|
||||
(update-in [:shapes 2] dissoc :group))
|
||||
(let [initial {:workspace {:selected #{}}
|
||||
:pages {1 {:id 1 :shapes [1 3]}}
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [2]}
|
||||
2 {:id 2 :page 1 :group 1 :type :group :items [4]}
|
||||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1 :group 2}}}
|
||||
|
||||
expected {:workspace {:selected #{}},
|
||||
:pages {1 {:id 1, :shapes [2 3]}},
|
||||
:shapes {2 {:id 2, :page 1, :type :group, :items [4]},
|
||||
3 {:id 3, :page 1},
|
||||
4 {:id 4, :page 1, :group 2}}}
|
||||
result (impl/drop-shape initial 2 1 :after)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
|
@ -227,47 +238,45 @@
|
|||
(t/is (vector? (get-in result [:pages 1 :shapes])))))
|
||||
|
||||
;; drop shape: move shape to neested group
|
||||
|
||||
(t/deftest drop-shape-test8
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 5 6]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2]}
|
||||
2 {:id 2 :page 1
|
||||
:group 1
|
||||
:type :group
|
||||
:items [3 4]}
|
||||
3 {:id 3 :page 1 :group 2}
|
||||
4 {:id 4 :page 1 :group 2}
|
||||
5 {:id 5 :page 1}
|
||||
6 {:id 6 :page 1}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [1 5])
|
||||
(update-in [:shapes 2 :items] conj 6)
|
||||
(update-in [:shapes 6] assoc :group 2))
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [2]}
|
||||
2 {:id 2 :page 1 :type :group :group 1 :items [3 4]}
|
||||
3 {:id 3 :page 1 :group 2}
|
||||
4 {:id 4 :page 1 :group 2}
|
||||
5 {:id 5 :page 1}
|
||||
6 {:id 6 :page 1}}}
|
||||
|
||||
expected {:pages {1 {:id 1, :shapes [1 5]}},
|
||||
:shapes {1 {:id 1, :page 1, :type :group, :items [2]},
|
||||
2 {:id 2, :page 1, :type :group, :group 1, :items [3 4 6]},
|
||||
3 {:id 3, :page 1, :group 2},
|
||||
4 {:id 4, :page 1, :group 2},
|
||||
5 {:id 5, :page 1},
|
||||
6 {:id 6, :page 1, :group 2}}}
|
||||
result (impl/drop-shape initial 6 4 :after)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
(t/is (= result expected))))
|
||||
|
||||
;; drop shape: move shape to neested group
|
||||
|
||||
(t/deftest drop-shape-test9
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2 5 6]}
|
||||
2 {:id 2 :page 1
|
||||
:group 1
|
||||
:type :group
|
||||
:items [3 4]}
|
||||
3 {:id 3 :page 1 :group 2}
|
||||
4 {:id 4 :page 1 :group 2}
|
||||
5 {:id 5 :page 1 :group 1}
|
||||
6 {:id 6 :page 1 :group 1}}}
|
||||
expected (-> initial
|
||||
(assoc-in [:pages 1 :shapes] [1])
|
||||
(assoc-in [:shapes 2 :items] [3 4 6])
|
||||
(assoc-in [:shapes 1 :items] [2 5])
|
||||
(update-in [:shapes 6] assoc :group 2))
|
||||
:shapes {1 {:id 1 :page 1 :type :group :items [2 5 6]}
|
||||
2 {:id 2 :page 1 :type :group :group 1 :items [3 4]}
|
||||
3 {:id 3 :page 1 :group 2}
|
||||
4 {:id 4 :page 1 :group 2}
|
||||
5 {:id 5 :page 1 :group 1}
|
||||
6 {:id 6 :page 1 :group 1}}}
|
||||
expected {:pages {1 {:id 1, :shapes [1]}},
|
||||
:shapes {1 {:id 1, :page 1, :type :group, :items [2 5]},
|
||||
2 {:id 2, :page 1, :type :group, :group 1, :items [3 4 6]},
|
||||
3 {:id 3, :page 1, :group 2},
|
||||
4 {:id 4, :page 1, :group 2},
|
||||
5 {:id 5, :page 1, :group 1},
|
||||
6 {:id 6, :page 1, :group 2}}}
|
||||
result (impl/drop-shape initial 6 4 :after)]
|
||||
;; (pprint expected)
|
||||
;; (pprint result)
|
||||
|
@ -299,8 +308,10 @@
|
|||
(t/is (= result expected))))
|
||||
|
||||
;; delete shape: delete from group
|
||||
|
||||
(t/deftest delete-shape-test2
|
||||
(let [initial {:pages {1 {:id 1 :shapes [1 3 4]}}
|
||||
(let [initial {:workspace {:selected #{}}
|
||||
:pages {1 {:id 1 :shapes [1 3 4]}}
|
||||
:shapes {1 {:id 1 :page 1
|
||||
:type :group
|
||||
:items [2]}
|
||||
|
@ -308,7 +319,8 @@
|
|||
3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
shape (get-in initial [:shapes 2])
|
||||
expected {:pages {1 {:id 1 :shapes [3 4]}}
|
||||
expected {:workspace {:selected #{}}
|
||||
:pages {1 {:id 1 :shapes [3 4]}}
|
||||
:shapes {3 {:id 3 :page 1}
|
||||
4 {:id 4 :page 1}}}
|
||||
result (impl/dissoc-shape initial shape)]
|
||||
|
|
Loading…
Add table
Reference in a new issue