diff --git a/frontend/src/app/main/data/workspace/edition.cljs b/frontend/src/app/main/data/workspace/edition.cljs index 5e36dc1771..c617de5f1d 100644 --- a/frontend/src/app/main/data/workspace/edition.cljs +++ b/frontend/src/app/main/data/workspace/edition.cljs @@ -15,6 +15,8 @@ (declare clear-edition-mode) +;; FIXME: rename to `enter-edition-mode` + (defn start-edition-mode "Mark a shape in edition mode" [id] @@ -42,6 +44,8 @@ ;; update namespace reference in the ;; app/main/data/workspace/path/undo.cljs file. +;; FIXME: rename to `exit-edition-mode` + (defn clear-edition-mode [] (ptk/reify ::clear-edition-mode diff --git a/frontend/src/app/main/data/workspace/path/changes.cljs b/frontend/src/app/main/data/workspace/path/changes.cljs index d766487e7e..0b9e0ee538 100644 --- a/frontend/src/app/main/data/workspace/path/changes.cljs +++ b/frontend/src/app/main/data/workspace/path/changes.cljs @@ -17,14 +17,12 @@ (defn generate-path-changes "Generates changes to update the new content of the shape" - [it objects page-id shape old-content new-content] + [it objects page-id shape-id old-content new-content] (assert (path/content? old-content)) (assert (path/content? new-content)) - (let [shape-id (:id shape) - - ;; We set the old values so the update-shapes works + (let [;; We set the old values so the update-shapes works objects (update objects shape-id (fn [shape] @@ -82,7 +80,7 @@ shape (st/get-path state)] (if (and (some? old-content) (some? (:id shape))) - (let [changes (generate-path-changes it objects page-id shape old-content (:content shape))] + (let [changes (generate-path-changes it objects page-id id old-content (:content shape))] (rx/of (dch/commit-changes changes))) (rx/empty))))))) diff --git a/frontend/src/app/main/data/workspace/path/drawing.cljs b/frontend/src/app/main/data/workspace/path/drawing.cljs index d7a5409f1b..53d40c3aef 100644 --- a/frontend/src/app/main/data/workspace/path/drawing.cljs +++ b/frontend/src/app/main/data/workspace/path/drawing.cljs @@ -17,6 +17,7 @@ [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.shape.layout :as ctl] + [app.main.data.changes :as dch] [app.main.data.helpers :as dsh] [app.main.data.workspace.drawing.common :as dwdc] [app.main.data.workspace.edition :as dwe] @@ -225,7 +226,7 @@ (rx/of (finish-drag))))))) (defn- start-edition - [_id] + [id] (ptk/reify ::start-edition ptk/UpdateEvent (update [_ state] @@ -351,6 +352,8 @@ (let [id (dm/get-in state [:workspace-local :edition]) objects (dsh/lookup-page-objects state) content (dm/get-in objects [id :content])] + (prn "start-draw-mode" id) + (if content (update-in state [:workspace-local :edit-path id] assoc :old-content content) state))) @@ -359,14 +362,15 @@ (watch [_ _ _] (rx/of (start-draw-mode*))))) -(defn start-draw-mode* - [] +(defn- start-draw-mode* + [id] (ptk/reify ::start-draw-mode* ptk/WatchEvent (watch [_ state stream] (let [local (get state :workspace-local) id (get local :edition) mode (dm/get-in local [:edit-path id :edit-mode])] + (prn "start-draw-mode*" id) (if (= :draw mode) (rx/concat @@ -376,7 +380,7 @@ (rx/filter (ptk/type? ::end-edition)) (rx/take 1) (rx/mapcat (fn [_] - (rx/of (check-changed-content) + (rx/of (check-changed-content id) (start-draw-mode*)))))) (rx/empty)))))) @@ -386,7 +390,7 @@ ptk/UpdateEvent (update [_ state] (if-let [id (dm/get-in state [:workspace-local :edition])] - (d/update-in-when state [:workspace-local :edit-path id] assoc :edit-mode mode) + (update-in state [:workspace-local :edit-path id] assoc :edit-mode mode) state)) ptk/WatchEvent @@ -407,21 +411,27 @@ (assoc-in state [:workspace-local :edit-path id :prev-handler] nil))))) (defn check-changed-content - [] + [id] (ptk/reify ::check-changed-content ptk/WatchEvent - (watch [_ state _] - (let [id (st/get-path-id state) - content (st/get-path state :content) - old-content (get-in state [:workspace-local :edit-path id :old-content]) - mode (get-in state [:workspace-local :edit-path id :edit-mode]) - empty-content? (empty? content)] + (watch [it state _] + (let [ + ;; id (st/get-path-id state) + content (st/get-path state :content) + empty-content? (empty? content) + + local (get-in state [:workspace-local :edit-path id]) + old-content (get local :old-content) + edit-mode (get local :edit-mode)] (cond (and (not= content old-content) (not empty-content?)) - (rx/of (changes/save-path-content)) + (let [page-id (:current-page-id state) + objects (dsh/lookup-page-objects state page-id) + changes (changes/generate-path-changes it objects page-id id old-content content)] + (rx/of (dch/commit-changes changes))) - (= mode :draw) + (= :draw edit-mode) (rx/of :interrupt) :else diff --git a/frontend/src/app/main/data/workspace/path/edition.cljs b/frontend/src/app/main/data/workspace/path/edition.cljs index 1210111f71..1dc6dccf7d 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -65,7 +65,7 @@ point-change (->> (map hash-map old-points new-points) (reduce merge))] (when (and (some? new-content) (some? shape)) - (let [changes (changes/generate-path-changes it objects page-id shape (:content shape) new-content)] + (let [changes (changes/generate-path-changes it objects page-id (:id shape) (:content shape) new-content)] (if (empty? new-content) (rx/of (dch/commit-changes changes) (dwe/clear-edition-mode)) @@ -338,19 +338,25 @@ (defn split-segments [{:keys [from-p to-p t]}] (ptk/reify ::split-segments - ptk/UpdateEvent - (update [_ state] - (let [id (st/get-path-id state) - content (st/get-path state :content)] - (-> state - (assoc-in [:workspace-local :edit-path id :old-content] content) - (st/set-content (-> content - (path.segment/split-segments #{from-p to-p} t) - (path/content)))))) - ptk/WatchEvent - (watch [_ _ _] - (rx/of (changes/save-path-content {:preserve-move-to true}))))) + (watch [it state _] + (let [page-id (get state :current-page-id) + objects (dsh/lookup-page-objects state page-id) + + shape (st/get-path state) + shape-id (get shape :id) + old-content (get shape :content) + + new-content (-> old-content + (path.segment/split-segments #{from-p to-p} t) + (path/content)) + changes (changes/generate-path-changes it objects page-id shape-id old-content new-content)] + + + (prn "split-segments" old-content) + (prn "split-segments" new-content) + + (rx/of (dch/commit-changes changes)))))) (defn create-node-at-position [event] diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index 0fd108f41c..8a3c8c8438 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -44,7 +44,7 @@ (path/close-subpaths)) changes - (changes/generate-path-changes it objects page-id shape (:content shape) new-content)] + (changes/generate-path-changes it objects page-id (:id shape) (:content shape) new-content)] (rx/concat (rx/of (dwsh/update-shapes [id] path/convert-to-path)