From a84b23168d931cff49d95b62b969cbbabc9511ed Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 16 Jan 2024 16:29:04 +0100 Subject: [PATCH] :bug: Fix problem with path editor undoing changes --- CHANGES.md | 1 + .../app/main/data/workspace/path/common.cljs | 6 ++- .../app/main/data/workspace/path/drawing.cljs | 8 ++-- .../app/main/data/workspace/path/helpers.cljs | 2 - .../app/main/data/workspace/persistence.cljs | 44 ++++++++++--------- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dfdc9b87c..738b261ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,7 @@ - Fix pixelated thumbnails [Github #3681](https://github.com/penpot/penpot/issues/3681) [Github #3661](https://github.com/penpot/penpot/issues/3661) - Fix problem with not applying colors to boards [Github #3941](https://github.com/penpot/penpot/issues/3941) +- Fix problem with path editor undoing changes [Github #3998](https://github.com/penpot/penpot/issues/3998) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace/path/common.cljs b/frontend/src/app/main/data/workspace/path/common.cljs index 689248412..8edd06ffe 100644 --- a/frontend/src/app/main/data/workspace/path/common.cljs +++ b/frontend/src/app/main/data/workspace/path/common.cljs @@ -7,6 +7,7 @@ (ns app.main.data.workspace.path.common (:require [app.common.schema :as sm] + [app.common.svg.path.subpath :as ups] [app.main.data.workspace.path.state :as st] [potok.v2.core :as ptk])) @@ -52,10 +53,11 @@ (dissoc state :last-point :prev-handler :drag-handler :preview)) (defn finish-path - [_source] + [] (ptk/reify ::finish-path ptk/UpdateEvent (update [_ state] (let [id (st/get-path-id state)] (-> state - (update-in [:workspace-local :edit-path id] clean-edit-state)))))) + (update-in [:workspace-local :edit-path id] clean-edit-state) + (update-in (st/get-path-location state :content) ups/close-subpaths)))))) diff --git a/frontend/src/app/main/data/workspace/path/drawing.cljs b/frontend/src/app/main/data/workspace/path/drawing.cljs index 64007cc8f..2e926e315 100644 --- a/frontend/src/app/main/data/workspace/path/drawing.cljs +++ b/frontend/src/app/main/data/workspace/path/drawing.cljs @@ -153,7 +153,7 @@ drag-events-stream (rx/of (finish-drag)) (rx/of (close-path-drag-end)))) - (rx/of (common/finish-path "close-path"))))))) + (rx/of (common/finish-path))))))) (defn close-path-drag-end [] (ptk/reify ::close-path-drag-end @@ -253,7 +253,7 @@ (rx/of (common/init-path)) (rx/merge mousemove-events mousedown-events) - (rx/of (common/finish-path "after-events"))))))) + (rx/of (common/finish-path))))))) (defn setup-frame [] (ptk/reify ::setup-frame @@ -362,7 +362,7 @@ (not= content old-content) (rx/of (changes/save-path-content) (start-draw-mode)) (= mode :draw) (rx/of :interrupt) - :else (rx/of (common/finish-path "changed-content"))))))) + :else (rx/of (common/finish-path))))))) (defn change-edit-mode [mode] (ptk/reify ::change-edit-mode @@ -376,7 +376,7 @@ (watch [_ state _] (let [id (st/get-path-id state)] (cond - (and id (= :move mode)) (rx/of (common/finish-path "change-edit-mode")) + (and id (= :move mode)) (rx/of (common/finish-path)) (and id (= :draw mode)) (rx/of (dwc/hide-toolbar) (start-draw-mode)) :else (rx/empty)))))) diff --git a/frontend/src/app/main/data/workspace/path/helpers.cljs b/frontend/src/app/main/data/workspace/path/helpers.cljs index de955f0f1..2facaf53a 100644 --- a/frontend/src/app/main/data/workspace/path/helpers.cljs +++ b/frontend/src/app/main/data/workspace/path/helpers.cljs @@ -12,7 +12,6 @@ [app.common.geom.shapes :as gsh] [app.common.math :as mth] [app.common.svg.path.command :as upc] - [app.common.svg.path.subpath :as ups] [app.main.data.workspace.path.common :as common] [app.util.mouse :as mse] [potok.v2.core :as ptk])) @@ -117,7 +116,6 @@ (let [command (next-node shape position prev-point prev-handler)] (-> shape (update :content (fnil conj []) command) - (update :content ups/close-subpaths) (update-selrect)))) (defn angle-points [common p1 p2] diff --git a/frontend/src/app/main/data/workspace/persistence.cljs b/frontend/src/app/main/data/workspace/persistence.cljs index b506c13bc..8cfc5a87f 100644 --- a/frontend/src/app/main/data/workspace/persistence.cljs +++ b/frontend/src/app/main/data/workspace/persistence.cljs @@ -234,7 +234,7 @@ (= (ptk/type event) ::changes-persisted)) (defn shapes-changes-persisted - [file-id {:keys [revn changes]}] + [file-id {:keys [revn changes] persisted-session-id :session-id}] (dm/assert! (uuid? file-id)) (dm/assert! (int? revn)) (dm/assert! (cpc/check-changes! changes)) @@ -245,24 +245,28 @@ ;; NOTE: we don't set the file features context here because ;; there are no useful context for code that need to be executed ;; on the frontend side - - (if-let [current-file-id (:current-file-id state)] - (if (= file-id current-file-id) - (let [changes (group-by :page-id changes)] + (let [current-file-id (:current-file-id state) + current-session-id (:session-id state)] + (if (and (some? current-file-id) + ;; If the remote change is from teh current session we skip + (not= persisted-session-id current-session-id)) + (if (= file-id current-file-id) + (let [changes (group-by :page-id changes)] + (-> state + (update-in [:workspace-file :revn] max revn) + (update :workspace-data + (fn [file] + (loop [fdata file + entries (seq changes)] + (if-let [[page-id changes] (first entries)] + (recur (-> fdata + (cpc/process-changes changes) + (cond-> (some? page-id) + (ctst/update-object-indices page-id))) + (rest entries)) + fdata)))))) (-> state - (update-in [:workspace-file :revn] max revn) - (update :workspace-data (fn [file] - (loop [fdata file - entries (seq changes)] - (if-let [[page-id changes] (first entries)] - (recur (-> fdata - (cpc/process-changes changes) - (cond-> (some? page-id) - (ctst/update-object-indices page-id))) - (rest entries)) - fdata)))))) - (-> state - (update-in [:workspace-libraries file-id :revn] max revn) - (update-in [:workspace-libraries file-id :data] cpc/process-changes changes))) + (update-in [:workspace-libraries file-id :revn] max revn) + (update-in [:workspace-libraries file-id :data] cpc/process-changes changes))) - state)))) + state)))))