diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 5b0ef09..c7093a8 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -585,18 +585,24 @@ (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. + "The selection a paste goes by: the selection, except in Figma's two cases. - 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." + A paste goes into what is selected and selects what it made. Pasting again + onto your own paste therefore means another one beside it, not one inside the + last — so while the selection is still exactly what the last paste made, it + goes where that one went. And pasting with the very thing you copied still + selected means a copy of it beside it: inside itself is a cycle, and was + refused. 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])))) + (let [{:keys [made from]} (get-in db [:ui :paste]) + primary (get-in db [:ui :selection]) + path (nth primary 3 nil) + copied (into #{} (map :path) (get-in db [:ui :clipboard :items]))] + (cond + (and made (= made (current-selections db))) from + (and (seq path) (contains? copied path)) (let [up (pop (vec path))] + [:node nil (peek up) up]) + :else primary))) (defn paste-destination "The effective creation context at the playhead, in the destination's frames." diff --git a/frontend/test/arthur/events/lane_test.cljs b/frontend/test/arthur/events/lane_test.cljs index f7a9154..fcadbea 100644 --- a/frontend/test/arthur/events/lane_test.cljs +++ b/frontend/test/arthur/events/lane_test.cljs @@ -323,7 +323,11 @@ :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}}}} + :playback {:in 0 :speed 1 :end :stop}} + :other {:id :other :kind :instance :z "b" + :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]))] @@ -333,17 +337,35 @@ (rf/dispatch-sync [::ui/copy]) (rf/dispatch-sync [::ui/select [:node :main nil []]]) (rf/dispatch-sync [::ui/paste]) - (is (= 2 (instances :main))) + (is (= 3 (instances :main))) (rf/dispatch-sync [::ui/paste]) (rf/dispatch-sync [::ui/paste]) - (is (= 4 (instances :main)) + (is (= 5 (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]]]) + (rf/dispatch-sync [::ui/select [:node :main :other [:other]]]) (is (= :inside (:sid (ui/paste-destination @rf-db/app-db (:clip (store/entry id)) {}))))))) +(deftest pasting-onto-what-you-copied-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-copied")] + (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/paste]) + (is (= 2 (count (get-in (store/entry id) [:clip :symbols :main :nodes]))) + "a symbol pasted with itself selected lands beside it, not refused as a cycle"))) + (deftest multi-paste-uses-one-current-primary-target-and-selects-the-batch (let [doc (fixture/document) id (store/install! {:clip doc :store {}} "multi-paste-target")