🐛 Remap nested grid reset cells through their near-main references

Use each paired child's shape-ref directly. Resolving it through its own
component can select a different nesting level and move the child into an
earlier auto cell. Fix F134.

The regression moved column 2 to column 1 before the fix; all 3 assertions
now pass. Benchmark ratios against Phase 1e: main 10/100/1000
0.46/0.52/0.53; three levels 0.47; chain 0.51; library 0.51;
many shapes 0.49; variant switch 0.61. No regression flag.

AI-assisted-by: GPT-6
This commit is contained in:
alonso.torres 2026-10-23 14:52:22 +02:00
parent 6831417993
commit 8a034be8fd
2 changed files with 28 additions and 3 deletions

View File

@ -1317,7 +1317,7 @@
(defn- update-grid-copy-attrs
"Synchronizes the `layout-grid-cells` property from the main shape to the copies"
[changes shape-copy-id shape-main library component omit-touched?]
[changes shape-copy-id shape-main _library _component omit-touched?]
(-> changes
(pcb/apply-changes-local)
(pcb/update-shapes
@ -1329,8 +1329,10 @@
(map #(get objects %))
(keep
(fn [copy-shape]
(let [main-shape (ctf/get-ref-shape library component copy-shape)]
[(:id main-shape) (:id copy-shape)]))))
;; Paired children refer to this near main, which can
;; belong to another component when resetting nested copies.
(when-let [ref (:shape-ref copy-shape)]
[ref (:id copy-shape)]))))
(:shapes shape-copy))
remove-orphan-cells

View File

@ -22,10 +22,33 @@
[app.common.test-helpers.shapes :as ths]
[app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl]
[clojure.test :as t]))
(t/use-fixtures :each thi/test-fixture)
(t/deftest reset-a-nested-grid-keeps-the-near-mains-manual-cell
(let [file (-> (thf/sample-file :file1)
(tho/add-grid-frame :inner-root)
(tho/add-rect :inner-child :parent-label :inner-root)
(tho/place-in-grid-columns :inner-root 2 {1 :inner-child})
(thc/make-component :inner :inner-root)
(tho/add-frame :outer-root)
(thc/instantiate-component :inner :nested :parent-label :outer-root
:children-labels [:nested-child])
(thc/make-component :outer :outer-root)
(thc/instantiate-component :outer :copy
:children-labels [:copy-nested :copy-child]))
initial (tm/make-situation file)
moved (-> initial (r/step (n/move-to-cell :nested :nested-child 1 2)) r/settle)
reset (-> moved (r/step (n/reset :copy-nested)) r/settle)
column (fn [s]
(let [head (tm/resolve-shape s :copy-nested)]
(:column (ctl/get-cell-by-shape-id head (first (:shapes head))))))]
(t/is (= 2 (column moved)))
(t/is (= 2 (column reset)))
(t/is (nil? (:touched (tm/resolve-shape reset :copy-nested))))))
(t/deftest reset-a-nested-copy-through-a-deleted-outer-main
(let [initial (setup/nested-component-with-copy)
edited (-> initial