From 476e53744e44c2df3cdeea75568d655d4c7d4ddc Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 19 Nov 2026 10:03:56 +0100 Subject: [PATCH] :bug: 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 --- .../app/main/data/workspace/clipboard.cljs | 8 ++++-- .../logic/pasting_in_containers_test.cljs | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/data/workspace/clipboard.cljs b/frontend/src/app/main/data/workspace/clipboard.cljs index d9113d8a8b..3911c08436 100644 --- a/frontend/src/app/main/data/workspace/clipboard.cljs +++ b/frontend/src/app/main/data/workspace/clipboard.cljs @@ -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] diff --git a/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs b/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs index 46602ebf2c..1390af5237 100644 --- a/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs +++ b/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs @@ -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