diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index d0cd0614aa..c72b09bcbf 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -436,7 +436,15 @@ new-selrect (-> new-points (gco/transform-points sr-transform) - (grc/points->rect))] + (grc/points->rect)) + + preserve-unflipped + (fn [after attr] + (if (or (get group attr) (get after attr)) + after + (if (contains? group attr) + (assoc after attr (get group attr)) + (dissoc after attr))))] ;; Updates the shape and the applytransform-rect will update the other properties (-> group @@ -448,7 +456,11 @@ ;; need to remove the flip flags (assoc :flip-x false) (assoc :flip-y false) - (apply-transform (gmt/matrix))))) + (apply-transform (gmt/matrix)) + ;; Regrouping still recalculates real flips. An unchanged unflipped + ;; axis keeps its nil/false/absent value for exact undo and redo. + (preserve-unflipped :flip-x) + (preserve-unflipped :flip-y)))) (defn update-mask-selrect [masked-group children] diff --git a/common/test/common_tests/geom_shapes_test.cljc b/common/test/common_tests/geom_shapes_test.cljc index 7a3023522b..f99b0f527d 100644 --- a/common/test/common_tests/geom_shapes_test.cljc +++ b/common/test/common_tests/geom_shapes_test.cljc @@ -39,6 +39,25 @@ :height 20} params))))) +(t/deftest regrouping-preserves-the-representation-of-unflipped-axes + (doseq [horizontal [{} {:flip-x nil} {:flip-x false}] + vertical [{} {:flip-y nil} {:flip-y false}]] + (let [group (merge (dissoc (create-test-shape :group) :flip-x :flip-y) horizontal vertical) + child (create-test-shape :rect) + after (gsh/update-group-selrect group [child])] + (t/is (= (select-keys group [:flip-x :flip-y]) (select-keys after [:flip-x :flip-y]))) + (t/is (gsh/close-attrs? :points (:points child) (:points after) 1e-10)) + (t/is (= (select-keys after [:flip-x :flip-y]) + (select-keys (gsh/update-group-selrect after [child]) [:flip-x :flip-y])))))) + +(t/deftest regrouping-still-recalculates-stale-flip-flags + (let [group (create-test-shape :group {:flip-x true :flip-y true}) + child (create-test-shape :rect) + after (gsh/update-group-selrect group [child])] + (t/is (false? (:flip-x after))) + (t/is (false? (:flip-y after))) + (t/is (gsh/close-attrs? :points (:points child) (:points after) 1e-10)))) + (t/deftest transform-shapes (t/testing "Shape without modifiers should stay the same" (t/are [type] diff --git a/common/test/common_tests/logic/comp_sync_test.cljc b/common/test/common_tests/logic/comp_sync_test.cljc index 4cc2fbdaa8..36cf9e5a21 100644 --- a/common/test/common_tests/logic/comp_sync_test.cljc +++ b/common/test/common_tests/logic/comp_sync_test.cljc @@ -891,6 +891,40 @@ (t/is (= (:shapes copy-group) (:shapes copy-group''))) (t/is (= (geometry copy-group) (geometry copy-group''))))) +(t/deftest test-sync-new-child-follows-an-overridden-group-frame + (let [file (-> (thf/sample-file :file1) + (add-group-component-with-copy) + (touch-copy-group-geometry) + (ths/add-sample-shape :free-shape :x 60 :y 60 :width 10 :height 10)) + page (thf/current-page file) + changes1 (cls/generate-relocate (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page))) + (thi/id :main-group) 0 #{(thi/id :free-shape)}) + updated-file (-> (thf/apply-changes file changes1) + (update-fill :main-child1 "#fabada")) + changes2 (sync-file-changes updated-file) + file' (thf/apply-changes updated-file changes2) + file'' (thf/apply-undo-changes file' changes2) + redone (thf/apply-changes file'' changes2) + copy-group (ths/get-shape file :copy-group) + copy-group' (ths/get-shape file' :copy-group) + added (ths/get-shape-by-id file' (first (:shapes copy-group')))] + ;; The main grew from 30x10 to 60x60. The copy keeps its authored frame; + ;; its new child follows the resulting 1/2 and 1/6 size ratios. + (t/is (= (geometry copy-group) (geometry copy-group'))) + (t/is (= #{:geometry-group} (:touched copy-group'))) + (t/is (= (thi/id :free-shape) (:shape-ref added))) + (t/is (gsh/close-attrs? :points + [(gpt/point 135 (/ 355.0 3)) (gpt/point 140 (/ 355.0 3)) + (gpt/point 140 120) (gpt/point 135 120)] + (:points added) 1e-10)) + (t/is (nil? (:touched added))) + (doseq [label [:copy-child1 :copy-child2]] + (t/is (= (geometry (ths/get-shape file label)) (geometry (ths/get-shape file' label)))) + (t/is (= #{:geometry-group} (:touched (ths/get-shape file' label))))) + (t/is (uc/same-state? (uc/snapshot updated-file) (uc/snapshot file''))) + (t/is (uc/same-state? (uc/snapshot file') (uc/snapshot redone))))) + (t/deftest test-sync-undo-group-after-remove-and-update (let [;; ==== Setup file (-> (thf/sample-file :file1)