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 []))))))))
|
||||
|
||||
(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."
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue