mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Give a pasted nested copy only the overrides of the refs it skips
A nested copy pasted out of its copy advances its refs to the component it copies and takes the touched groups of the references it skips, so it keeps the values they gave it. The clipboard also took those of its new reference: a pasted rect then overrode a fill its new reference itself overrides, and stopped following that reference's later edits. A shape with no touched group was also left an empty touched set, which an undo then removed, so undo did not restore the state exactly (F589). `advance-copied-objects` takes only the touched groups of the references between the shape and its new one, and leaves no touched set when there are none. The golden master's case AZ, which pastes such a copy, records its states again: its pasted head no longer has an empty touched set. Test (copying-and-duplicating-test, fails before the fix): `a-pasted-nested-copy-takes-only-the-overrides-of-the-references-it-skips`. Benchmark (bench-components, alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 22.2 | 22.701 | 0.63 | | edit-through-a-chain-of-dependents | 68.931 | 43.557 | 45.725 | 0.63 | | library-update-into-copies | 83.083 | 52.452 | 54.294 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.766 | 2.895 | 0.57 | | main-edit-into-10-copies | 1.79 | 1.142 | 1.178 | 0.64 | | main-edit-into-100-copies | 15.415 | 11.615 | 12.834 | 0.75 | | main-edit-into-1000-copies | 153.086 | 106.297 | 109.039 | 0.69 | | variant-switch-into-copies | 32.052 | 23.09 | 23.778 | 0.72 | AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
e0d5912c0a
commit
dddbdab107
@ -453,16 +453,22 @@
|
||||
advance-shape (fn [level-delta objects shape]
|
||||
(let [new-shape-ref (ctf/advance-shape-ref file page libraries shape level-delta
|
||||
{:include-deleted? true})]
|
||||
(cond-> objects
|
||||
(and (some? new-shape-ref) (not= new-shape-ref (:shape-ref shape)))
|
||||
(-> (assoc-in [(:id shape) :shape-ref] new-shape-ref)
|
||||
(assoc-in [(:id shape) :touched]
|
||||
(set/union
|
||||
(if (and (some? new-shape-ref) (not= new-shape-ref (:shape-ref shape)))
|
||||
(let [;; the references between the shape and its new one
|
||||
skipped (->> (ctf/get-ref-chain-until-target-ref container libraries shape new-shape-ref)
|
||||
rest
|
||||
(remove #(= (:id %) new-shape-ref)))
|
||||
touched (set/union
|
||||
(or (:touched shape) #{})
|
||||
(cli/inherited-touched
|
||||
shape
|
||||
(ctf/get-touched-from-ref-chain-until-target-ref
|
||||
container libraries shape new-shape-ref))))))))
|
||||
(into #{} (mapcat :touched) skipped)))]
|
||||
(-> (assoc-in objects [(:id shape) :shape-ref] new-shape-ref)
|
||||
;; a shape with no touched group has no touched set
|
||||
(update (:id shape) #(if (seq touched)
|
||||
(assoc % :touched touched)
|
||||
(dissoc % :touched)))))
|
||||
objects)))
|
||||
detach-copy (fn [objects shape]
|
||||
(reduce #(update %1 %2 ctk/detach-shape)
|
||||
objects
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
(:require
|
||||
[app.common.files.changes :as ch]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.logic.duplicate :as cld]
|
||||
[app.common.logic.libraries :as cll]
|
||||
@ -157,3 +158,26 @@
|
||||
;; - Change color of the copy you duplicated from, and check that it's NOT PROPAGATED.
|
||||
(tho/update-bottom-color :group-3 "#333333" :propagate-fn propagate-all-component-changes)
|
||||
(validate #(t/is (= (count-shapes % "rect-simple-1" "#333333") 2)))))
|
||||
|
||||
(t/deftest a-pasted-nested-copy-takes-only-the-overrides-of-the-references-it-skips
|
||||
;; the nested copy of :c2 that a copy of :c3 holds, pasted out of it, refers
|
||||
;; to the main of :c2, whose nested rect overrides its fill; the pasted rect
|
||||
;; shows that fill without overriding it, and keeps no touched set
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-two-levels-nested-component-with-copy
|
||||
:c1 :main1-root :main1-child
|
||||
:c2 :main2-root :nested-head1
|
||||
:c3 :main3-root :nested-head2 :nested-subhead2
|
||||
:copy3
|
||||
:nested-head1-params {:children-labels [:nested-rect1]}
|
||||
:copy2-root-params {:children-labels [:copy-head2 :copy-subhead2 :copy-rect]})
|
||||
(tho/update-color :nested-rect1 "#111111"))
|
||||
page (thf/current-page file)
|
||||
objects (:objects page)
|
||||
ids (cfh/get-children-ids-with-self objects (thi/id :copy-head2))
|
||||
copied (cld/advance-copied-objects file page {(:id file) file}
|
||||
(select-keys objects ids) [(thi/id :copy-head2)])
|
||||
rect (get copied (thi/id :copy-rect))]
|
||||
(t/is (= #{:fill-group} (:touched (get objects (thi/id :nested-rect1)))))
|
||||
(t/is (= (thi/id :nested-rect1) (:shape-ref rect)))
|
||||
(t/is (not (contains? rect :touched)) (pr-str (:touched rect)))))
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n add-tokens {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> skip\n apply-token {:target #fn, :token-name \"radius.l\", :value 30}\n test\n unapply-token {:target #fn, :token-name \"radius.l\"}", :states ["2bcdf6d40b47eea3" "3dabf53ca39c6d4d" "af5ac8a5ea672f3b"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n add-tokens {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> skip\n apply-token {:target #fn, :token-name \"radius.l\", :value 30}\n test\n one-of -> skip", :states ["2bcdf6d40b47eea3" "0d34ab60457acb76"]}]
|
||||
:az
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n paste-to-root {:target #fn, :new-head 5}\n test\n change-property {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["c8c845596f55aa86" "1d1b26cfc6a035e4" "cdcb72926d45d3db" "c6ccfcd10b8e16a3"]}
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n paste-to-root {:target #fn, :new-head 5}\n test\n change-property {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["c8c845596f55aa86" "0d2b7d7efc6e54d1" "8956d8fac4c6c4fb" "30c4e5a8979ec07f"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> skip\n paste-to-root {:target #fn, :new-head 3}\n test\n change-property {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["c8c845596f55aa86" "a6a97a3d3298a63a" "a47933c7e373dfd7" "75123b44e98d2e2c"]}]
|
||||
:b
|
||||
[{:transcript "change-property {:target :copy-child, :property :fills, :value \"#00ff00\"}\n change-property {:target :main-child, :property :fills, :value \"#ff0000\"}", :states ["5df508d97af5247a" "b2f66a15e5ff4097" "4b24ab56135742f0"]}]
|
||||
|
||||
@ -82,7 +82,7 @@
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:target #fn, :token-name \"radius.l\", :value 30}\n \n {:target #fn, :token-name \"radius.l\"}", :states ["d0de1c63d1e2913a" "8e2ae96c4495f143" "608fefc00332c877"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:target #fn, :token-name \"radius.l\", :value 30}\n \n one-of -> ", :states ["d0de1c63d1e2913a" "a3e49f56de0aaf82"]}]
|
||||
:case-az-copy-moved-out-of-its-main-keeps-inherited-overrides
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:target #fn, :new-head 5}\n \n {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["d6802c2361c4f48a" "09526a373b2bf78d" "f6588d21ee3f82ea" "89696ef8abcbb71d"]}
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:target #fn, :new-head 5}\n \n {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["d6802c2361c4f48a" "2ec99a7c1c3a764e" "63398e5920c78a16" "c26f774147ed5d8c"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> \n {:target #fn, :new-head 3}\n \n {:target #fn, :property :fills, :value \"#ff0000\"}", :states ["d6802c2361c4f48a" "7443c8f4406f3704" "78edc4e41925495c" "62c32614a4d51244"]}]
|
||||
:case-b-copy-override-survives-later-main-change
|
||||
[{:transcript " {:target :copy-child, :property :fills, :value \"#00ff00\"}\n {:target :main-child, :property :fills, :value \"#ff0000\"}", :states ["83d0e402abf3aafe" "89465e6b1fc243c5" "009c37e0db2f75d7"]}]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user