diff --git a/common/app/common/geom/point.cljc b/common/app/common/geom/point.cljc index 9752f32be..6d78d283a 100644 --- a/common/app/common/geom/point.cljc +++ b/common/app/common/geom/point.cljc @@ -38,7 +38,7 @@ ([v] (cond (point? v) - v + (Point. (:x v) (:y v)) (number? v) (point v v) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 9c3807563..c8f4c3393 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -364,7 +364,7 @@ (let [edition (get-in state [:workspace-local :edition]) drawing (get state :workspace-drawing)] ;; Editors handle their own undo's - (when-not (or (some? edition) (some? drawing)) + (when-not (or (some? edition) (not-empty drawing)) (let [undo (:workspace-undo state) items (:items undo) index (or (:index undo) (dec (count items)))] @@ -379,7 +379,7 @@ (watch [_ state stream] (let [edition (get-in state [:workspace-local :edition]) drawing (get state :workspace-drawing)] - (when-not (or (some? edition) (some? drawing)) + (when-not (or (some? edition) (not-empty drawing)) (let [undo (:workspace-undo state) items (:items undo) index (or (:index undo) (dec (count items)))] diff --git a/frontend/src/app/main/data/workspace/path/changes.cljs b/frontend/src/app/main/data/workspace/path/changes.cljs index 84e2de574..2d046fe6d 100644 --- a/frontend/src/app/main/data/workspace/path/changes.cljs +++ b/frontend/src/app/main/data/workspace/path/changes.cljs @@ -44,25 +44,30 @@ :shapes [shape-id]}]] [rch uch])) -(defn save-path-content [] - (ptk/reify ::save-path-content - ptk/UpdateEvent - (update [_ state] - (let [content (get-in state (st/get-path state :content)) - content (if (= (-> content last :command) :move-to) - (into [] (take (dec (count content)) content)) - content)] - (assoc-in state (st/get-path state :content) content))) +(defn save-path-content + ([] + (save-path-content {})) - ptk/WatchEvent - (watch [_ state stream] - (let [id (get-in state [:workspace-local :edition]) - old-content (get-in state [:workspace-local :edit-path id :old-content])] - (if (some? old-content) - (let [shape (get-in state (st/get-path state)) - page-id (:current-page-id state) - [rch uch] (generate-path-changes page-id shape old-content (:content shape))] - (rx/of (dwc/commit-changes rch uch {:commit-local? true}))) - (rx/empty)))))) + ([{:keys [preserve-move-to] :or {preserve-move-to false}}] + (ptk/reify ::save-path-content + ptk/UpdateEvent + (update [_ state] + (let [content (get-in state (st/get-path state :content)) + content (if (and (not preserve-move-to) + (= (-> content last :command) :move-to)) + (into [] (take (dec (count content)) content)) + content)] + (assoc-in state (st/get-path state :content) content))) + + ptk/WatchEvent + (watch [_ state stream] + (let [id (get-in state [:workspace-local :edition]) + old-content (get-in state [:workspace-local :edit-path id :old-content])] + (if (some? old-content) + (let [shape (get-in state (st/get-path state)) + page-id (:current-page-id state) + [rch uch] (generate-path-changes page-id shape old-content (:content shape))] + (rx/of (dwc/commit-changes rch uch {:commit-local? true}))) + (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 08de690f7..80ed8631d 100644 --- a/frontend/src/app/main/data/workspace/path/drawing.cljs +++ b/frontend/src/app/main/data/workspace/path/drawing.cljs @@ -136,8 +136,9 @@ handlers (-> (upc/content->handlers content) (get position)) - [idx prefix] (when (= (count handlers) 1) (first handlers)) - + [idx prefix] (when (= (count handlers) 1) + (first handlers)) + drag-events-stream (->> (streams/position-stream snap-toggled points) (rx/take-until stop-stream) diff --git a/frontend/src/app/main/data/workspace/path/edition.cljs b/frontend/src/app/main/data/workspace/path/edition.cljs index eb6a63eb2..bea694816 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -224,9 +224,12 @@ (ptk/reify ::create-node-at-position ptk/UpdateEvent (update [_ state] - (let [id (st/get-path-id state)] - (update-in state (st/get-path state :content) upt/split-segments #{from-p to-p} t))) + (let [id (st/get-path-id state) + old-content (get-in state (st/get-path state :content))] + (-> state + (assoc-in [:workspace-local :edit-path id :old-content] old-content) + (update-in (st/get-path state :content) upt/split-segments #{from-p to-p} t)))) ptk/WatchEvent (watch [_ state stream] - (rx/of (changes/save-path-content))))) + (rx/of (changes/save-path-content {:preserve-move-to true}))))) diff --git a/frontend/src/app/main/data/workspace/path/helpers.cljs b/frontend/src/app/main/data/workspace/path/helpers.cljs index a1f81e51d..85d0c5870 100644 --- a/frontend/src/app/main/data/workspace/path/helpers.cljs +++ b/frontend/src/app/main/data/workspace/path/helpers.cljs @@ -87,7 +87,8 @@ (defn next-node "Calculates the next-node to be inserted." [shape position prev-point prev-handler] - (let [last-command (-> shape :content last :command) + (let [position (select-keys position [:x :y]) + last-command (-> shape :content last :command) add-line? (and prev-point (not prev-handler) (not= last-command :close-path)) add-curve? (and prev-point prev-handler (not= last-command :close-path))] (cond diff --git a/frontend/src/app/main/data/workspace/path/selection.cljs b/frontend/src/app/main/data/workspace/path/selection.cljs index 903954da3..93bb59e66 100644 --- a/frontend/src/app/main/data/workspace/path/selection.cljs +++ b/frontend/src/app/main/data/workspace/path/selection.cljs @@ -50,7 +50,6 @@ id (get-in state [:workspace-local :edition]) content (get-in state (st/get-path state :content)) selected-point? #(gsh/has-point-rect? selrect %) - selected-points (get-in state [:workspace-local :edit-path id :selected-points]) positions (into (if shift? selected-points #{}) diff --git a/frontend/src/app/main/data/workspace/path/undo.cljs b/frontend/src/app/main/data/workspace/path/undo.cljs index 2c490ecba..0301b47d3 100644 --- a/frontend/src/app/main/data/workspace/path/undo.cljs +++ b/frontend/src/app/main/data/workspace/path/undo.cljs @@ -10,6 +10,7 @@ [app.common.data.undo-stack :as u] [app.common.uuid :as uuid] [app.main.data.workspace.path.state :as st] + [app.main.data.workspace.path.changes :as changes] [app.main.store :as store] [beicon.core :as rx] [okulary.core :as l] @@ -26,20 +27,26 @@ (defn- make-entry [state] (let [id (st/get-path-id state)] {:content (get-in state (st/get-path state :content)) + :selrect (get-in state (st/get-path state :selrect)) + :points (get-in state (st/get-path state :points)) :preview (get-in state [:workspace-local :edit-path id :preview]) :last-point (get-in state [:workspace-local :edit-path id :last-point]) :prev-handler (get-in state [:workspace-local :edit-path id :prev-handler])})) -(defn- load-entry [state {:keys [content preview last-point prev-handler]}] - (let [id (st/get-path-id state)] +(defn- load-entry [state {:keys [content selrect points preview last-point prev-handler]}] + (let [id (st/get-path-id state) + old-content (get-in state (st/get-path state :content))] (-> state (d/assoc-in-when (st/get-path state :content) content) + (d/assoc-in-when (st/get-path state :selrect) selrect) + (d/assoc-in-when (st/get-path state :points) points) (d/update-in-when [:workspace-local :edit-path id] assoc :preview preview :last-point last-point - :prev-handler prev-handler)))) + :prev-handler prev-handler + :old-content old-content)))) (defn undo [] (ptk/reify ::undo @@ -54,7 +61,11 @@ (-> (load-entry entry) (d/assoc-in-when [:workspace-local :edit-path id :undo-stack] - undo-stack))))))) + undo-stack))))) + + ptk/WatchEvent + (watch [_ state stream] + (rx/of (changes/save-path-content))))) (defn redo [] (ptk/reify ::redo @@ -68,7 +79,11 @@ (load-entry entry) (d/assoc-in-when [:workspace-local :edit-path id :undo-stack] - undo-stack)))))) + undo-stack)))) + + ptk/WatchEvent + (watch [_ state stream] + (rx/of (changes/save-path-content))))) (defn add-undo-entry [] (ptk/reify ::add-undo-entry diff --git a/frontend/src/app/util/path/commands.cljs b/frontend/src/app/util/path/commands.cljs index e899cf85e..9800b7772 100644 --- a/frontend/src/app/util/path/commands.cljs +++ b/frontend/src/app/util/path/commands.cljs @@ -165,9 +165,14 @@ (point->handlers ) (filter (fn [[ci cp]] (and (not= index ci) (not= prefix cp)) )))] - (when (= (count handlers) 1) - (->> handlers - first)))) + (cond + (= (count handlers) 1) + (->> handlers first) + + (and (= :c1 prefix) (= (count content) index)) + [(dec index) :c2] + + :else nil))) (defn get-commands