From 6d0b36e9b94333536adf7b8359c4f175298f7677 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 26 May 2021 10:41:12 +0200 Subject: [PATCH] :bug: Fix problem with new nodes in paths --- CHANGES.md | 1 + frontend/src/app/util/path/tools.cljs | 32 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3a0659912..d010a459d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -36,6 +36,7 @@ - Fix issue when group creation leaves an empty group [#1724](https://tree.taiga.io/project/penpot/issue/1724) - Fix problem with :multiple for colors and typographies [#1668](https://tree.taiga.io/project/penpot/issue/1668) - Fix problem with locked shapes when change parents [#974](https://github.com/penpot/penpot/issues/974) +- Fix problem with new nodes in paths [#978](https://github.com/penpot/penpot/issues/978) ### :arrow_up: Deps updates diff --git a/frontend/src/app/util/path/tools.cljs b/frontend/src/app/util/path/tools.cljs index c352196b5..4f0110786 100644 --- a/frontend/src/app/util/path/tools.cljs +++ b/frontend/src/app/util/path/tools.cljs @@ -164,11 +164,12 @@ [content points] (let [point-set (set points)] - (loop [segments [] - prev-point nil + (loop [segments [] + prev-point nil start-point nil - cur-cmd (first content) - content (rest content)] + index 0 + cur-cmd (first content) + content (rest content)] (let [;; Close-path makes a segment from the last point to the initial path point cur-point (if (= :close-path (:command cur-cmd)) @@ -191,12 +192,16 @@ segments (cond-> segments is-segment? - (conj [prev-point cur-point cur-cmd]))] + (conj {:start prev-point + :end cur-point + :cmd cur-cmd + :index index}))] (if (some? cur-cmd) (recur segments cur-point start-point + (inc index) (first content) (rest content)) @@ -205,12 +210,13 @@ (defn split-segments "Given a content creates splits commands between points with new segments" [content points value] + (let [split-command - (fn [[start end cmd]] + (fn [{:keys [start end cmd index]}] (case (:command cmd) - :line-to [cmd (upg/split-line-to start cmd value)] - :curve-to [cmd (upg/split-curve-to start cmd value)] - :close-path [cmd [(upc/make-line-to (gpt/line-val start end value)) cmd]] + :line-to [index (upg/split-line-to start cmd value)] + :curve-to [index (upg/split-curve-to start cmd value)] + :close-path [index [(upc/make-line-to (gpt/line-val start end value)) cmd]] nil)) cmd-changes @@ -219,12 +225,12 @@ (filter (comp not nil?))))) process-segments - (fn [command] - (if (contains? cmd-changes command) - (get cmd-changes command) + (fn [[index command]] + (if (contains? cmd-changes index) + (get cmd-changes index) [command]))] - (into [] (mapcat process-segments) content))) + (into [] (mapcat process-segments) (d/enumerate content)))) (defn remove-nodes "Removes from content the points given. Will try to reconstruct the paths