mirror of
https://github.com/penpot/penpot.git
synced 2026-11-23 19:00:36 +00:00
🐛 Wait for a mouse position before moving a dragged asset
Dragging a component from the Assets panel onto a freshly opened file showed "Something wrong has happened". The drag starts a move as soon as it enters the viewport, and the move took the mouse position at once, which is nil until the pointer has been over the viewport; the vector from the start point to it failed (`gpt/subtract` assertion). The copy was still created. The move now waits for the first mouse position. Found by the components Qase run (PENPOT-2416). Test: `a-move-started-without-a-mouse-position-follows-the-pointer` (drag-on-save-failure-test). AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
476e53744e
commit
36f0f3089d
@ -881,7 +881,10 @@
|
||||
target-objects-siblings
|
||||
(with-target-frames exclude-frames-siblings)
|
||||
|
||||
;; An asset dragged from the sidebar starts its move before the
|
||||
;; pointer has been over the viewport, with no position yet.
|
||||
position (->> ms/mouse-position
|
||||
(rx/filter some?)
|
||||
(rx/map #(gpt/to-vec from-position %)))
|
||||
|
||||
snap-delta
|
||||
|
||||
@ -41,8 +41,9 @@
|
||||
|
||||
(defn- ^:async drag
|
||||
"Drags rect1 with the gesture `start` makes, from (120, 220) to (160, 260),
|
||||
then emits `stop`. Resolves to the commits made and the store."
|
||||
[start stop]
|
||||
then emits `stop`. Resolves to the commits made and the store. The mouse
|
||||
position is `initial` when the gesture starts, (120, 220) by default."
|
||||
[start stop & {:keys [initial] :or {initial (gpt/point 120 220)}}]
|
||||
(let [file (-> (cthf/sample-file :file1)
|
||||
(ctho/add-rect :rect1 :x 100 :y 200 :width 50 :height 50))
|
||||
rect (cths/get-shape file :rect1)
|
||||
@ -59,7 +60,7 @@
|
||||
;; Moves a DOM node the tests lack
|
||||
dwt/set-ghost-displacement (mock/stub (fn [_] (ptk/data-event ::ghost-moved)))}
|
||||
(try
|
||||
(rx/push! ms/mouse-position (gpt/point 120 220))
|
||||
(rx/push! ms/mouse-position initial)
|
||||
(ptk/emit! store
|
||||
#(assoc-in % [:workspace-local :selected] (d/ordered-set (:id rect)))
|
||||
(start rect))
|
||||
@ -98,6 +99,14 @@
|
||||
(t/is (pos? commits))
|
||||
(t/is (= 140 (:x (shape-rect store))))))
|
||||
|
||||
;; Scenario: an asset dragged from the sidebar starts its move before the
|
||||
;; pointer has been over the viewport, so there is no mouse position yet.
|
||||
;; Proves: the move waits for the first position instead of failing.
|
||||
(t/deftest ^:async a-move-started-without-a-mouse-position-follows-the-pointer
|
||||
(let [{:keys [commits store]} (await (drag move :interrupt :initial nil))]
|
||||
(t/is (pos? commits))
|
||||
(t/is (= 140 (:x (shape-rect store))))))
|
||||
|
||||
;; Scenario: saves fail while the user drags a shape, or rotates it. Proves:
|
||||
;; the lock cancels the gesture, the shape goes back to where it was and
|
||||
;; nothing is committed behind the failed save.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user