From ee328dfcb9133a3c1576b1a99ccb8a47ac2a25e3 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Thu, 26 Nov 2026 14:20:39 +0100 Subject: [PATCH] :bug: Sync the bool type of a copy with the type it ends with (#13337) * :bug: Keep the bool type of a moved copy when its main becomes a group :type is synced with the geometry group and :bool-type with the content group. When the main bool became a group and the copy had its geometry touched, the copy kept :type :bool but lost :bool-type, and the backend rejected it as an invalid shape. Sync :bool-type with the geometry group, next to :type and the path content it defines. AI-assisted-by: claude-opus-5-5 * :bug: Sync the bool type of a copy with the type it ends with From the review: moving :bool-type to the geometry group stopped a new bool operation of the main from reaching any moved copy, and dropped the operation overrides stored as content-group touched. Keep :bool-type in the content group. In update-attrs, work out the type the copy ends with (its own when the geometry group is touched): a bool never loses its :bool-type, and any other type gets none. Tests cover a moved copy when the main becomes a group, a new operation reaching a moved copy, a moved group copy when the main becomes a bool, and an operation override on a copy. AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 25 ++++- .../common_tests/logic/comp_sync_test.cljc | 105 ++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 6b248af87d..e49607934b 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2061,7 +2061,16 @@ ;; In case of subinstances, the comparison is always done with the ;; near component, because this is that we are syncing with. origin-shape (reposition-shape origin-shape origin-root dest-root) - touched (get dest-shape :touched #{})] + touched (get dest-shape :touched #{}) + + ;; :type and :bool-type sync with different groups. The copy keeps + ;; its own :type when that group is touched, so :bool-type must + ;; follow the type the copy ends with, not the main: a bool always + ;; keeps one, any other type has none. + type-group (ctk/resolve-sync-group (:type origin-shape) :type) + synced-type (if (and omit-touched? (touched type-group)) + (:type dest-shape) + (:type origin-shape))] (loop [attrs updatable-attrs roperations [] @@ -2130,6 +2139,20 @@ :else (get origin-shape attr))) + [skip-operations? attr-val] + (cond + (not= attr :bool-type) + [skip-operations? attr-val] + + (not= synced-type :bool) + [false nil] + + (nil? attr-val) + [true nil] + + :else + [skip-operations? attr-val]) + ;; If the final attr-value is the actual value, skip skip-operations? (or skip-operations? diff --git a/common/test/common_tests/logic/comp_sync_test.cljc b/common/test/common_tests/logic/comp_sync_test.cljc index c26b2d5ec6..9f062cecca 100644 --- a/common/test/common_tests/logic/comp_sync_test.cljc +++ b/common/test/common_tests/logic/comp_sync_test.cljc @@ -23,6 +23,7 @@ [app.common.types.components-list :as ctkl] [app.common.types.container :as ctn] [app.common.types.modifiers :as ctm] + [app.common.types.path :as path] [app.common.types.shape-tree :as ctst] [clojure.test :as t])) @@ -871,6 +872,110 @@ (t/is (= #{} (changes-attrs sync-changes))) (t/is (empty? (:redo-changes sync-changes))))) +(t/deftest test-sync-bool-to-group-keeps-bool-type-in-a-moved-copy + ;; A copy with its geometry touched keeps its :type when the main bool + ;; becomes a group. :bool-type must stay with it: syncing its removal + ;; left a bool without :bool-type, which the backend rejects. + (let [;; ==== Setup + file (-> (file-with-bool-component) + (move-shapes [:copy-bool :copy-p1 :copy-p2] (gpt/point 5 0))) + page (thf/current-page file) + + ;; ==== Action + updated-file (thf/apply-changes file + (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(thi/id :main-bool)} + (fn [shape] + (-> shape + (assoc :type :group) + (dissoc :bool-type) + (gsh/update-group-selrect (mapv (d/getf (:objects page)) (:shapes shape))))) + (:objects page) + {})) + file' (thf/apply-changes updated-file (sync-file-changes updated-file)) + + ;; ==== Get + copy-bool' (ths/get-shape file' :copy-bool)] + + ;; ==== Check + (t/is (= #{:geometry-group} (:touched copy-bool'))) + (t/is (= :bool (:type copy-bool'))) + (t/is (= :union (:bool-type copy-bool'))))) + +(defn- update-shape-with + [file label update-fn] + (let [page (thf/current-page file)] + (thf/apply-changes file + (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(thi/id label)} + update-fn + (:objects page) + {})))) + +(t/deftest test-sync-bool-type-change-to-a-moved-copy + ;; Moving a copy touches its geometry, not its bool operation, so a new + ;; operation in the main still reaches it. + (let [;; ==== Setup + file (-> (file-with-bool-component) + (move-shapes [:copy-bool :copy-p1 :copy-p2] (gpt/point 5 0))) + + ;; ==== Action + updated-file (update-shape-with file :main-bool #(assoc % :bool-type :difference)) + file' (thf/apply-changes updated-file (sync-file-changes updated-file)) + + ;; ==== Get + copy-bool' (ths/get-shape file' :copy-bool)] + + ;; ==== Check + (t/is (= :bool (:type copy-bool'))) + (t/is (= :difference (:bool-type copy-bool'))))) + +(t/deftest test-sync-group-to-bool-adds-no-bool-type-to-a-moved-copy + ;; A moved copy of a group stays a group when its main becomes a bool, + ;; so it must not get the main's :bool-type. + (let [;; ==== Setup + content [{:command :move-to :params {:x 10 :y 10}} + {:command :line-to :params {:x 24 :y 10}} + {:command :line-to :params {:x 17 :y 24}} + {:command :close-path}] + file (-> (thf/sample-file :file1) + (tho/add-frame :main-root) + (tho/add-group :main-group :parent-label :main-root) + (ths/add-sample-shape :main-p1 :type :path :parent-label :main-group :content content) + (ths/add-sample-shape :main-p2 :type :path :parent-label :main-group :content content) + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root {:children-labels [:copy-group :copy-p1 :copy-p2]}) + (move-shapes [:copy-group :copy-p1 :copy-p2] (gpt/point 5 0))) + + ;; ==== Action + updated-file (update-shape-with file :main-group #(assoc % :type :bool :bool-type :union :content (path/content content))) + file' (thf/apply-changes updated-file (sync-file-changes updated-file)) + + ;; ==== Get + copy-group' (ths/get-shape file' :copy-group)] + + ;; ==== Check + (t/is (= :group (:type copy-group'))) + (t/is (not (contains? copy-group' :bool-type))))) + +(t/deftest test-sync-keeps-a-bool-type-override-on-a-copy + ;; An operation chosen on the copy is an override: a new operation in + ;; the main must not replace it. + (let [;; ==== Setup + file (-> (file-with-bool-component) + (update-shape-with :copy-bool #(assoc % :bool-type :difference))) + + ;; ==== Action + updated-file (update-shape-with file :main-bool #(assoc % :bool-type :intersection)) + file' (thf/apply-changes updated-file (sync-file-changes updated-file)) + + ;; ==== Get + copy-bool' (ths/get-shape file' :copy-bool)] + + ;; ==== Check + (t/is (contains? (:touched copy-bool') :content-group)) + (t/is (= :difference (:bool-type copy-bool'))))) + (t/deftest test-sync-bool-content-change-inside-main ;; Moving only the bool inside its main is a real change and must sync. (let [;; ==== Action