mirror of
https://github.com/penpot/penpot.git
synced 2026-11-23 19:00:36 +00:00
🐛 Paste at the viewport center before the pointer reaches it
Ctrl+V in a freshly opened file, with nothing selected, pasted nothing until the pointer had been over the viewport: the paste took the mouse position, which is nil until then, and failed on it. Pasting shapes and HTML text now falls back to the center of the viewport when there is no mouse position, as pasting path nodes already does. Found by the components Qase run. Test: `paste-before-the-pointer-reaches-the-viewport-uses-its-center` (pasting-in-containers-test). AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
604998a716
commit
476e53744e
@ -906,7 +906,10 @@
|
||||
|
||||
variant-props (:variant-properties pdata)
|
||||
|
||||
position (deref ms/mouse-position)
|
||||
;; Before the pointer has been over the viewport there is
|
||||
;; no mouse position, so the paste goes to its center.
|
||||
position (or (deref ms/mouse-position)
|
||||
(dsh/get-viewport-center state))
|
||||
|
||||
;; Replace mode is only valid with a single selected shape.
|
||||
;; In that case we drop the pasted content at its position and
|
||||
@ -1049,7 +1052,8 @@
|
||||
(gsh/shape->center frame-object))
|
||||
|
||||
:else
|
||||
(deref ms/mouse-position)))
|
||||
(or (deref ms/mouse-position)
|
||||
(dsh/get-viewport-center state))))
|
||||
|
||||
(defn- paste-html-text
|
||||
[html]
|
||||
|
||||
@ -132,6 +132,32 @@
|
||||
;; ==== Check
|
||||
(t/is (= (:parent-id copied-blue1') (:id frame-red')))))))))
|
||||
|
||||
(t/deftest paste-before-the-pointer-reaches-the-viewport-uses-its-center
|
||||
"With no mouse position yet, a paste with nothing selected lands at the
|
||||
center of the viewport."
|
||||
(t/async
|
||||
done
|
||||
(let [file (-> (cthf/sample-file :file1)
|
||||
(ctho/add-frame :frame-red {:name "frame-red"}))
|
||||
store (ths/setup-store file)
|
||||
page (cthf/current-page file)
|
||||
frame (cths/get-shape file :frame-red)
|
||||
pdata (thp/simulate-copy-shape #{(:id frame)} (:objects page) {(:id file) file} page file #{} 67)
|
||||
_ (rx/push! ms/mouse-position nil)
|
||||
events [#(assoc-in % [:workspace-local :vbox] {:x 0 :y 0 :width 1000 :height 800})
|
||||
(dws/deselect-all)
|
||||
(dw/paste-shapes pdata)]]
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [page' (cthf/current-page (ths/get-file-from-state new-state))
|
||||
copied (->> (vals (:objects page'))
|
||||
(filter #(and (= "frame-red" (:name %)) (not= (:id frame) (:id %))))
|
||||
first)]
|
||||
(t/is (some? copied))
|
||||
(t/is (= 500 (:x copied)))
|
||||
(t/is (= 400 (:y copied)))))))))
|
||||
|
||||
(t/deftest copy-shape-to-component
|
||||
"Coping a rect into a component results in a copy of the rect inside the component"
|
||||
(t/async
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user