Paste onto your own paste goes beside it

A paste selects what it made, and went into what was selected, so pasting
a symbol twice nested the second copy inside the first. Figma's rule:
while the selection is still exactly what the last paste made, paste goes
where that one went. Select anything else and it follows the selection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FLuCjp9kNH6ovwJVXSbq9
This commit is contained in:
Olive Vaughn 2026-10-10 23:18:21 -04:00
parent 831843aeb0
commit 2f6fde26fb
2 changed files with 49 additions and 6 deletions

View file

@ -584,11 +584,25 @@
(edit/transaction (constantly (:clip r))) (edit/transaction (constantly (:clip r)))
(select-results [])))))))) (select-results []))))))))
(defn- paste-anchor
"The selection a paste goes by: the selection, unless it is still exactly
what the last paste made, and then whatever that paste went by.
FIGMA'S RULE. A paste goes into what is selected and selects what it made,
so without this pasting a symbol twice put the second copy inside the first,
and a third inside that. Pasting again onto your own paste means another one
beside it; select anything else and paste follows the selection again."
[db]
(let [{:keys [made from]} (get-in db [:ui :paste])]
(if (and made (= made (current-selections db)))
from
(get-in db [:ui :selection]))))
(defn paste-destination (defn paste-destination
"The effective creation context at the playhead, in the destination's frames." "The effective creation context at the playhead, in the destination's frames."
[db clip st] [db clip st]
(creation/target clip st (get-in db [:ui :open]) (creation/target clip st (get-in db [:ui :open])
(get-in db [:ui :selection]) (editing-frame db clip))) (paste-anchor db) (editing-frame db clip)))
(rf/reg-event-db (rf/reg-event-db
::paste ::paste
@ -602,10 +616,11 @@
r (clipboard/paste clip payload sid frame {:fresh-id random-uuid})] r (clipboard/paste clip payload sid frame {:fresh-id random-uuid})]
(if-let [why (:refused r)] (if-let [why (:refused r)]
(command-refused db why) (command-refused db why)
(-> db (let [made (mapv (fn [id] [:node sid id (conj path id)]) (:roots r))]
(edit/transaction (constantly (:clip r))) (-> db
(select-results (edit/transaction (constantly (:clip r)))
(mapv (fn [id] [:node sid id (conj path id)]) (:roots r)))))))))) (select-results made)
(assoc-in [:ui :paste] {:from (paste-anchor db) :made made})))))))))
(defn- duplicate-selected [db unique?] (defn- duplicate-selected [db unique?]
(let [clip (:clip (store/entry (:clip/current db))) (let [clip (:clip (store/entry (:clip/current db)))

View file

@ -1,5 +1,5 @@
(ns arthur.events.lane-test (ns arthur.events.lane-test
(:require [cljs.test :refer [deftest is]] (:require [cljs.test :refer [deftest is testing]]
[arthur.domain.clip :as clip] [arthur.domain.clip :as clip]
[arthur.domain.creation :as creation] [arthur.domain.creation :as creation]
[arthur.domain.history :as history] [arthur.domain.history :as history]
@ -316,6 +316,34 @@
(select-keys (ui/paste-destination db doc nil) [:sid :path :frame])) (select-keys (ui/paste-destination db doc nil) [:sid :path :frame]))
"an inactive selected symbol falls back to the open symbol"))) "an inactive selected symbol falls back to the open symbol")))
(deftest pasting-onto-your-own-paste-goes-beside-it
(let [doc {:fps 24 :width 20 :height 20
:symbols
{:main {:id :main :frames 40
:nodes {:drawing {:id :drawing :kind :instance :z "a"
:span [0 10] :time {:at 0 :rate 1}
:source {:symbol :inside}
:playback {:in 0 :speed 1 :end :stop}}}}
:inside {:id :inside :frames 10 :nodes {}}}}
id (store/install! {:clip doc :store {}} "paste-beside")
instances #(count (get-in (store/entry id) [:clip :symbols % :nodes]))]
(reset! rf-db/app-db {:clip/current id :paint/revision 0
:ui {:open :main :selection [:node :main :drawing [:drawing]]}
:playback {:frame 2}})
(rf/dispatch-sync [::ui/copy])
(rf/dispatch-sync [::ui/select [:node :main nil []]])
(rf/dispatch-sync [::ui/paste])
(is (= 2 (instances :main)))
(rf/dispatch-sync [::ui/paste])
(rf/dispatch-sync [::ui/paste])
(is (= 4 (instances :main))
"the selected copy is a symbol under the playhead, and the paste still goes beside it")
(is (= 0 (instances :inside)))
(testing "selecting something else makes paste follow the selection again"
(rf/dispatch-sync [::ui/select [:node :main :drawing [:drawing]]])
(is (= :inside (:sid (ui/paste-destination @rf-db/app-db
(:clip (store/entry id)) {})))))))
(deftest multi-paste-uses-one-current-primary-target-and-selects-the-batch (deftest multi-paste-uses-one-current-primary-target-and-selects-the-batch
(let [doc (fixture/document) (let [doc (fixture/document)
id (store/install! {:clip doc :store {}} "multi-paste-target") id (store/install! {:clip doc :store {}} "multi-paste-target")