mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
📎 Predict a grid cell override kept by a switch between equal grids
A variant switch keeps a copy's grid cell overrides when the old and the new variant mains have identical grids: the same tracks and the same cells holding corresponding children. The component model never predicted it, since it compared the old main's cells, kept by id, with the new main's list of cells, so a kept override showed as a phantom. The model now carries the copy's cells whole in that case, with each child replaced by the new child at its path. Harness only; the benchmark is not run. Also in this commit: - Predict the end of a swap kept by a switch onto the same component. A variant switch keeps a child the copy swapped for another component, and when the new variant holds that same component at the child's place, the child becomes a plain copy of it: the swap ends, as the swap-group tests of a switch to a variant with the same component expect. The component model kept the swap override there. It now drops it for a kept swapped child whose new position has the same component. - The harness changes that check the next commit, "Carry no grid cells a switched copy already shows". AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
e0bbc50c32
commit
1b0137bde8
@ -642,9 +642,14 @@
|
||||
(reduce
|
||||
(fn [result shape]
|
||||
(if (and (not= root-id (:id shape)) (contains? before (:id shape)))
|
||||
;; A switch keeps an authored swapped subtree with its ids.
|
||||
(cond-> result (seq (get model (:id shape)))
|
||||
(assoc (:id shape) (get model (:id shape))))
|
||||
;; A switch keeps an authored swapped subtree with its ids; the
|
||||
;; swap ends where the new position holds the same component.
|
||||
(let [position (get after (:shape-ref shape))
|
||||
same? (and position
|
||||
(= (:component-id position) (:component-id shape))
|
||||
(= (:component-file position) (:component-file shape)))
|
||||
groups (cond-> (get model (:id shape)) same? (dissoc :swap-group))]
|
||||
(cond-> result (seq groups) (assoc (:id shape) groups)))
|
||||
(if-let [[main _] (source after new-paths new-main-id shape)]
|
||||
(let [path (get new-paths (:id main))
|
||||
[old old-main groups] (get old-copies path)
|
||||
@ -678,14 +683,44 @@
|
||||
{:content (:content old)})))]
|
||||
(reduce-kv
|
||||
(fn [result group _]
|
||||
(if-let [unit (get text-groups group)]
|
||||
(cond-> result
|
||||
(and (not (and (= unit :typography) mixed-typography?))
|
||||
(not (contains? text-differences unit))
|
||||
(or (and owned-typography? (contains? typography-units unit))
|
||||
(not (same-value? main group {:content (:content old)}))))
|
||||
(-> (assoc-in [(:id shape) group] {:content (:content old)})
|
||||
(assoc-in [(:id shape) :content-group] {})))
|
||||
(cond
|
||||
(= group :layout-grid-cells)
|
||||
;; cell overrides carry whole, and only between identical grids
|
||||
(let [path-cells (fn [grid paths]
|
||||
(into #{} (map #(update % :shapes (fn [ids] (mapv paths ids))))
|
||||
(grid/get-cells grid)))
|
||||
identical? (and old old-main
|
||||
(= (:layout-grid-rows old-main) (:layout-grid-rows main))
|
||||
(= (:layout-grid-columns old-main) (:layout-grid-columns main))
|
||||
(= (path-cells old-main old-paths) (path-cells main new-paths)))
|
||||
;; each old copy child, by its path, to the new copy child
|
||||
children (into {}
|
||||
(keep (fn [child-id]
|
||||
(when-let [[child-main _] (source after new-paths new-main-id
|
||||
(get after child-id))]
|
||||
(when-let [[old-child] (get old-copies (get new-paths (:id child-main)))]
|
||||
[(:id old-child) child-id]))))
|
||||
(:shapes shape))]
|
||||
(cond-> result
|
||||
(and identical?
|
||||
;; cells the new copy shows anyway are no override
|
||||
(not= (path-cells old (into {} (map (fn [[path [old-shape]]] [(:id old-shape) path]))
|
||||
old-copies))
|
||||
(path-cells main new-paths)))
|
||||
(assoc (:id shape) (merge (get result (:id shape))
|
||||
(grid/remap-groups {group (values old group)} children)))))
|
||||
|
||||
(contains? text-groups group)
|
||||
(let [unit (get text-groups group)]
|
||||
(cond-> result
|
||||
(and (not (and (= unit :typography) mixed-typography?))
|
||||
(not (contains? text-differences unit))
|
||||
(or (and owned-typography? (contains? typography-units unit))
|
||||
(not (same-value? main group {:content (:content old)}))))
|
||||
(-> (assoc-in [(:id shape) group] {:content (:content old)})
|
||||
(assoc-in [(:id shape) :content-group] {}))))
|
||||
|
||||
:else
|
||||
(let [attrs (get attributes group)
|
||||
same? (fn [a b]
|
||||
(cond
|
||||
|
||||
@ -1770,6 +1770,21 @@
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:style 0 1 1] [:make-variant 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest switching-a-copy-to-an-identical-grid-keeps-its-cell-override
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:grid-direction 0 0 0 1] [:grid-cell 0 0 0 1] [:swap 0 0 0 0] [:make-variant 4]
|
||||
[:switch 0]]}))))
|
||||
|
||||
(t/deftest switching-a-copy-ends-a-swap-its-new-variant-also-holds
|
||||
(t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout nil :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:make-variant 2] [:switch 0] [:variant-property 0 0 0 0] [:switch 4]
|
||||
[:variant-property 0 0 0 0] [:switch 1] [:make-variant 13 0 0 0]
|
||||
[:variant-property 0 0 0 0] [:switch 6]]}))))
|
||||
|
||||
(t/deftest random-variant-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user