mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Give a swapped child that stops filling its own component's size
A copy's child swapped for another component and set to fill takes the size the layout gives it. When a sync of its main set it back to fix, the swapped head only took its placement attributes and kept the filled size, where a full sync gives it its own component's size. A head with untouched geometry that stops filling in a direction is now synced with its own component; the sync context carries the file and the libraries for it. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 19.042 | 21.954 | 0.54 | | edit-through-a-chain-of-dependents | 68.931 | 39.697 | 41.13 | 0.58 | | library-update-into-copies | 83.083 | 49.796 | 50.704 | 0.6 | | main-edit-among-many-shapes | 4.837 | 2.3 | 2.482 | 0.48 | | main-edit-into-10-copies | 1.79 | 1.061 | 1.101 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.157 | 10.441 | 0.66 | | main-edit-into-1000-copies | 153.086 | 96.248 | 101.459 | 0.63 | | variant-switch-into-copies | 32.052 | 21.72 | 22.289 | 0.68 | Common suite: 2373 tests, 0 failures. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
25281f47f2
commit
53e1b7634f
@ -418,6 +418,8 @@
|
||||
:main-container main-container
|
||||
:component component
|
||||
:library library
|
||||
:file file
|
||||
:libraries libraries
|
||||
;; Reset also places new children in the main's frame.
|
||||
:root-inst (cond-> shape-inst reset? (dissoc :touched))
|
||||
:root-main shape-main
|
||||
@ -669,11 +671,12 @@
|
||||
are and only places a swapped child; a reset (`:reset?`) overwrites the
|
||||
overrides and clears them. `ctx` holds what stays the same along the
|
||||
walk: the copy's `:container`, the `:main-container` of the main shapes,
|
||||
the `:component` and its `:library`, the roots `:root-inst` and
|
||||
`:root-main`, and `:reset?`. The main shapes of the children of a copy
|
||||
shape that keeps its own geometry are placed like it first, so they get
|
||||
their expected geometry. The children of a grid copy with its own cells
|
||||
follow the flow of those cells instead of the main's order."
|
||||
the `:component` and its `:library`, the sync's `:file` and
|
||||
`:libraries`, the roots `:root-inst` and `:root-main`, and `:reset?`.
|
||||
The main shapes of the children of a copy shape that keeps its own
|
||||
geometry are placed like it first, so they get their expected geometry.
|
||||
The children of a grid copy with its own cells follow the flow of those
|
||||
cells instead of the main's order."
|
||||
[changes {:keys [container main-container component reset?] :as ctx} shape-inst shape-main]
|
||||
(shape-log :debug (:id shape-inst) container
|
||||
:msg "Sync shape direct recursive"
|
||||
@ -1856,15 +1859,30 @@
|
||||
|
||||
(defn- update-swapped-placement
|
||||
"Synchronizes a swapped copy head with the main shape it replaces, in the
|
||||
attributes that place it in its parent."
|
||||
[changes {:keys [root-inst root-main container]} shape-inst shape-main]
|
||||
(let [objects (:objects container)]
|
||||
(generate-take-placement changes
|
||||
shape-inst
|
||||
(reposition-shape shape-main root-main root-inst)
|
||||
objects
|
||||
(and (ctsl/any-layout-immediate-child? objects shape-inst)
|
||||
(not (ctsl/position-absolute? shape-inst))))))
|
||||
attributes that place it in its parent. A head with untouched geometry
|
||||
that stops filling its parent in a direction is synced with its own
|
||||
component, as the layout no longer sizes it."
|
||||
[changes {:keys [root-inst root-main container file libraries]} shape-inst shape-main]
|
||||
(let [objects (:objects container)
|
||||
changes (generate-take-placement changes
|
||||
shape-inst
|
||||
(reposition-shape shape-main root-main root-inst)
|
||||
objects
|
||||
(and (ctsl/any-layout-immediate-child? objects shape-inst)
|
||||
(not (ctsl/position-absolute? shape-inst))))
|
||||
sizings [:layout-item-h-sizing :layout-item-v-sizing]
|
||||
;; whether the layout may have sized the head
|
||||
filling? (and (not (ctk/touched-group? shape-inst :geometry-group))
|
||||
(some #(= :fill (get shape-inst %)) sizings))]
|
||||
(if filling?
|
||||
(let [changes (pcb/apply-changes-local changes)
|
||||
objects (pcb/get-objects changes)
|
||||
placed (get objects (:id shape-inst))]
|
||||
(if (some #(and (= :fill (get shape-inst %)) (not= :fill (get placed %))) sizings)
|
||||
(generate-sync-shape-direct changes file libraries (assoc container :objects objects)
|
||||
(:id shape-inst) false)
|
||||
changes))
|
||||
changes)))
|
||||
|
||||
(defn- update-layout-children
|
||||
"Copy into `dest`, a shape of `container`, the layout attributes of the
|
||||
|
||||
@ -7,12 +7,14 @@
|
||||
(ns common-tests.logic.comp-sync-layout-items-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[clojure.set :as set]
|
||||
[clojure.test :as t]))
|
||||
|
||||
@ -226,3 +228,29 @@
|
||||
", board1=" board-value
|
||||
", rect1=" rect-value)
|
||||
(run-case comp-value board-value rect-value))))
|
||||
|
||||
(t/deftest swapped-child-that-stops-filling-takes-its-component-size
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame :frame-small :width 100 :height 100)
|
||||
(thc/make-component :small :frame-small)
|
||||
(tho/add-frame :frame-big :width 140 :height 100)
|
||||
(thc/make-component :big :frame-big)
|
||||
(add-flex-frame :frame-main)
|
||||
(thc/instantiate-component :small :nested :parent-label :frame-main)
|
||||
(tho/change-shape :nested #(assoc % :layout-item-h-sizing :fill))
|
||||
(thc/make-component :main :frame-main)
|
||||
(thc/instantiate-component :main :copy :children-labels [:copy-nested])
|
||||
(tho/swap-component-in-shape :copy-nested :big :new-shape-label :copy-big)
|
||||
;; the width the layout gives the swapped child that fills
|
||||
(tho/change-shape :copy-big #(gsh/transform-shape % (ctm/change-size % 50 100))
|
||||
:ignore-touched true))
|
||||
file' (-> file
|
||||
(tho/change-shape :nested #(assoc % :layout-item-h-sizing :fix))
|
||||
(tho/propagate-component-changes :main))
|
||||
copy-big (ths/get-shape file :copy-big)
|
||||
copy-big' (ths/get-shape file' :copy-big)]
|
||||
(t/is (= :fill (:layout-item-h-sizing copy-big)))
|
||||
(t/is (== 50 (-> copy-big :selrect :width)))
|
||||
(t/is (= :fix (:layout-item-h-sizing copy-big')))
|
||||
(t/is (== 140 (:width copy-big')))
|
||||
(t/is (== 140 (-> copy-big' :selrect :width)))))
|
||||
|
||||
@ -1918,6 +1918,16 @@
|
||||
[:swap 11 0 0 0] [:make-variant 4] [:switch 9] [:switch 16 0 0 0]
|
||||
[:combine 7] [:switch 11]]}))))
|
||||
|
||||
(t/deftest resetting-a-fill-off-a-swapped-child-gives-it-its-own-size
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true
|
||||
:layout :flex :layout-item-margins false :grid-square false :library-depth 1
|
||||
:library true :rich-variants true :layout-children false :library-text true
|
||||
:grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:delete 26 0 0 0] [:delete 16] [:restore 16] [:delete 23] [:restore 23]
|
||||
[:swap 26 0 0 0] [:switch 0] [:nest 29 0 0 0] [:duplicate 3 0 0 0]
|
||||
[:reset 0 0 0 0] [:nest 14 0 0 0] [:switch 6 0 0 0] [:style 11 29 1]
|
||||
[:reset 2]]}))))
|
||||
|
||||
(t/deftest random-variant-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user