diff --git a/CHANGES.md b/CHANGES.md index 50063e39d1..64cada74c8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -69,6 +69,7 @@ - Fix shift+2 shortcut in MacOS with non-english keyboards [Taiga #3038](https://tree.taiga.io/project/penpot/issue/3038) - Some fixes to SVG imports [Taiga #3122](https://tree.taiga.io/project/penpot/issue/3122) [#1720](https://github.com/penpot/penpot/issues/1720) [Taiga #2884](https://tree.taiga.io/project/penpot/issue/2884) - Fix drag guides to delete target area [#1679](https://github.com/penpot/penpot/issues/1679) +- Fix undo when rotating groups [Taiga #3136](https://tree.taiga.io/project/penpot/issue/3136) ### :arrow_up: Deps updates ### :heart: Community contributions by (Thank you!) diff --git a/common/src/app/common/geom/matrix.cljc b/common/src/app/common/geom/matrix.cljc index f95726a160..40cd8d2764 100644 --- a/common/src/app/common/geom/matrix.cljc +++ b/common/src/app/common/geom/matrix.cljc @@ -57,6 +57,15 @@ (map (comp d/parse-double first)))] (apply matrix params))) +(defn close? + [m1 m2] + (and (mth/close? (.-a m1) (.-a m2)) + (mth/close? (.-b m1) (.-b m2)) + (mth/close? (.-c m1) (.-c m2)) + (mth/close? (.-d m1) (.-d m2)) + (mth/close? (.-e m1) (.-e m2)) + (mth/close? (.-f m1) (.-f m2)))) + (defn multiply ([^Matrix m1 ^Matrix m2] (let [m1a (.-a m1) diff --git a/common/src/app/common/geom/point.cljc b/common/src/app/common/geom/point.cljc index f79743f7a8..78c3771519 100644 --- a/common/src/app/common/geom/point.cljc +++ b/common/src/app/common/geom/point.cljc @@ -33,7 +33,6 @@ (s/def ::point (s/and (s/keys :req-un [::x ::y]) point?)) - (defn ^boolean point-like? [{:keys [x y] :as v}] (and (map? v) @@ -61,6 +60,11 @@ ([x y] (Point. x y))) +(defn close? + [p1 p2] + (and (mth/close? (:x p1) (:x p2)) + (mth/close? (:y p1) (:y p2)))) + (defn angle->point [{:keys [x y]} angle distance] (point (+ x (* distance (mth/cos angle))) diff --git a/common/src/app/common/geom/shapes/rect.cljc b/common/src/app/common/geom/shapes/rect.cljc index 0d36ad4a71..692c1d2ba0 100644 --- a/common/src/app/common/geom/shapes/rect.cljc +++ b/common/src/app/common/geom/shapes/rect.cljc @@ -34,6 +34,24 @@ :width width :height height}))) +(defn close-rect? + [rect1 rect2] + (and (mth/close? (:x rect1) (:x rect2)) + (mth/close? (:y rect1) (:y rect2)) + (mth/close? (:width rect1) (:width rect2)) + (mth/close? (:height rect1) (:height rect2)))) + +(defn close-selrect? + [selrect1 selrect2] + (and (mth/close? (:x selrect1) (:x selrect2)) + (mth/close? (:y selrect1) (:y selrect2)) + (mth/close? (:x1 selrect1) (:x1 selrect2)) + (mth/close? (:y1 selrect1) (:y1 selrect2)) + (mth/close? (:x2 selrect1) (:x2 selrect2)) + (mth/close? (:y2 selrect1) (:y2 selrect2)) + (mth/close? (:width selrect1) (:width selrect2)) + (mth/close? (:height selrect1) (:height selrect2)))) + (defn rect->points [{:keys [x y width height]}] (when (d/num? x y) (let [width (max width 0.01) diff --git a/common/src/app/common/pages/changes_builder.cljc b/common/src/app/common/pages/changes_builder.cljc index e30f19dcde..845e5afd18 100644 --- a/common/src/app/common/pages/changes_builder.cljc +++ b/common/src/app/common/pages/changes_builder.cljc @@ -8,8 +8,12 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.geom.matrix :as gmt] + [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.common.geom.shapes.bool :as gshb] + [app.common.geom.shapes.rect :as gshr] + [app.common.math :as mth] [app.common.pages :as cp] [app.common.pages.helpers :as cph] [app.common.uuid :as uuid])) @@ -379,8 +383,24 @@ generate-operation (fn [operations attr old new] (let [old-val (get old attr) - new-val (get new attr)] - (if (= old-val new-val) + new-val (get new attr) + + equal? (cond + (and (number? old-val) (number? new-val)) + (mth/close? old-val new-val) + + (and (gmt/matrix? old-val) (gmt/matrix? new-val)) + (gmt/close? old-val new-val) + + (= attr :points) + (every? #(apply gpt/close? %) (d/zip old-val new-val)) + + (= attr :selrect) + (gshr/close-selrect? old-val new-val) + + :else + (= old-val new-val))] + (if equal? operations (-> operations (update :rops conj {:type :set :attr attr :val new-val :ignore-touched true}) @@ -413,7 +433,7 @@ (if (seq rops) (-> changes (update :redo-changes conj (assoc change :operations rops)) - (update :undo-changes conj (assoc change :operations uops))) + (update :undo-changes d/preconj (assoc change :operations uops))) changes)))] (-> (reduce resize-parent changes all-parents)