diff --git a/CHANGES.md b/CHANGES.md index 78b4f28a3e..54df8056ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -92,6 +92,7 @@ example. It's still usable as before, we just removed the example. - Fix U and E icon displayed in project list [Taiga #12806](https://tree.taiga.io/project/penpot/issue/12806) - Fix unpublish library modal not scrolling a long file list [Taiga #12285](https://tree.taiga.io/project/penpot/issue/12285) - Fix incorrect interaction betwen hower and scroll on assets sidebar [Taiga #12389](https://tree.taiga.io/project/penpot/issue/12389) +- Fix switch variants with paths [Taiga #12841](https://tree.taiga.io/project/penpot/issue/12841) ## 2.11.1 diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 3734774932..4d7b0a59aa 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -12,8 +12,11 @@ [app.common.files.changes-builder :as pcb] [app.common.files.helpers :as cfh] [app.common.files.variant :as cfv] + [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] + [app.common.geom.rect :as grc] [app.common.geom.shapes :as gsh] + [app.common.geom.shapes.common :as gco] [app.common.logging :as log] [app.common.logic.shapes :as cls] [app.common.logic.variant-properties :as clvp] @@ -26,6 +29,7 @@ [app.common.types.library :as ctl] [app.common.types.page :as ctp] [app.common.types.pages-list :as ctpl] + [app.common.types.path.segment :as segment] [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.shape.interactions :as ctsi] @@ -1876,6 +1880,44 @@ roperations' uoperations'))))))) +(defn- set-path-new-values + [current-shape prev-shape transform] + (let [new-content (segment/transform-content + (:content current-shape) + (gmt/transform-in (gpt/point 0 0) transform)) + new-points (-> (segment/content->selrect new-content) + (grc/rect->points)) + points-center (gco/points->center new-points) + new-selrect (gsh/calculate-selrect new-points points-center) + shape (assoc current-shape + :content new-content + :points new-points + :selrect new-selrect) + + prev-center (segment/content-center (:content prev-shape)) + delta (gpt/subtract points-center (first new-points)) + new-pos (gpt/subtract prev-center delta)] + (gsh/absolute-move shape new-pos))) + +(defn- switch-path-change-value + [prev-shape ;; The shape before the switch + current-shape ;; The shape after the switch (a clean copy) + ref-shape ;; The referenced shape on the main component + ;; before the switch + attr] + (let [old-width (-> ref-shape :selrect :width) + new-width (-> prev-shape :selrect :width) + + old-height (-> ref-shape :selrect :height) + new-height (-> prev-shape :selrect :height) + + transform (-> (gpt/point (/ new-width old-width) + (/ new-height old-height)) + (gmt/scale-matrix)) + + shape (set-path-new-values current-shape prev-shape transform)] + (get shape attr))) + (defn- switch-text-change-value [prev-content ;; The :content of the text before the switch @@ -2027,6 +2069,10 @@ (= :content attr) (touched attr-group)) + path-change? + (and (= :path (:type current-shape)) + (contains? #{:points :selrect :content} attr)) + ;; position-data is a special case because can be affected by :geometry-group and :content-group ;; so, if the position-data changes but the geometry is touched we need to reset the position-data ;; so it's calculated again @@ -2055,6 +2101,12 @@ (:content origin-ref-shape) touched) + path-change? + (switch-path-change-value previous-shape + current-shape + origin-ref-shape + attr) + :else (get previous-shape attr)))