Paste with what you copied selected goes beside it
Copying a symbol and pasting straight away tried to put the copy inside the symbol itself, and was refused as a cycle. Figma's other case: with the copied thing still selected, paste goes into what holds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011FLuCjp9kNH6ovwJVXSbq9
This commit is contained in:
parent
c4040c789c
commit
2b9f8638d5
2 changed files with 42 additions and 14 deletions
|
|
@ -585,18 +585,24 @@
|
||||||
(select-results []))))))))
|
(select-results []))))))))
|
||||||
|
|
||||||
(defn- paste-anchor
|
(defn- paste-anchor
|
||||||
"The selection a paste goes by: the selection, unless it is still exactly
|
"The selection a paste goes by: the selection, except in Figma's two cases.
|
||||||
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,
|
A paste goes into what is selected and selects what it made. Pasting again
|
||||||
so without this pasting a symbol twice put the second copy inside the first,
|
onto your own paste therefore means another one beside it, not one inside the
|
||||||
and a third inside that. Pasting again onto your own paste means another one
|
last — so while the selection is still exactly what the last paste made, it
|
||||||
beside it; select anything else and paste follows the selection again."
|
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]
|
[db]
|
||||||
(let [{:keys [made from]} (get-in db [:ui :paste])]
|
(let [{:keys [made from]} (get-in db [:ui :paste])
|
||||||
(if (and made (= made (current-selections db)))
|
primary (get-in db [:ui :selection])
|
||||||
from
|
path (nth primary 3 nil)
|
||||||
(get-in db [:ui :selection]))))
|
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
|
(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."
|
||||||
|
|
|
||||||
|
|
@ -321,6 +321,10 @@
|
||||||
:symbols
|
:symbols
|
||||||
{:main {:id :main :frames 40
|
{:main {:id :main :frames 40
|
||||||
:nodes {:drawing {:id :drawing :kind :instance :z "a"
|
: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}}
|
||||||
|
:other {:id :other :kind :instance :z "b"
|
||||||
:span [0 10] :time {:at 0 :rate 1}
|
:span [0 10] :time {:at 0 :rate 1}
|
||||||
:source {:symbol :inside}
|
:source {:symbol :inside}
|
||||||
:playback {:in 0 :speed 1 :end :stop}}}}
|
:playback {:in 0 :speed 1 :end :stop}}}}
|
||||||
|
|
@ -333,17 +337,35 @@
|
||||||
(rf/dispatch-sync [::ui/copy])
|
(rf/dispatch-sync [::ui/copy])
|
||||||
(rf/dispatch-sync [::ui/select [:node :main nil []]])
|
(rf/dispatch-sync [::ui/select [:node :main nil []]])
|
||||||
(rf/dispatch-sync [::ui/paste])
|
(rf/dispatch-sync [::ui/paste])
|
||||||
(is (= 2 (instances :main)))
|
(is (= 3 (instances :main)))
|
||||||
(rf/dispatch-sync [::ui/paste])
|
(rf/dispatch-sync [::ui/paste])
|
||||||
(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")
|
"the selected copy is a symbol under the playhead, and the paste still goes beside it")
|
||||||
(is (= 0 (instances :inside)))
|
(is (= 0 (instances :inside)))
|
||||||
(testing "selecting something else makes paste follow the selection again"
|
(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
|
(is (= :inside (:sid (ui/paste-destination @rf-db/app-db
|
||||||
(:clip (store/entry id)) {})))))))
|
(: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
|
(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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue