diff --git a/frontend/src/app/main/data/workspace/path/changes.cljs b/frontend/src/app/main/data/workspace/path/changes.cljs index 8461b2e68..ba409228f 100644 --- a/frontend/src/app/main/data/workspace/path/changes.cljs +++ b/frontend/src/app/main/data/workspace/path/changes.cljs @@ -88,10 +88,10 @@ (let [objects (wsh/lookup-page-objects state) page-id (:current-page-id state) 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)) - [rch uch] (generate-path-changes objects page-id shape old-content (:content shape))] + old-content (get-in state [:workspace-local :edit-path id :old-content]) + shape (get-in state (st/get-path state))] + (if (and (some? old-content) (some? shape)) + (let [[rch uch] (generate-path-changes objects page-id shape old-content (:content shape))] (rx/of (dch/commit-changes {:redo-changes rch :undo-changes uch :origin it}))) diff --git a/frontend/src/app/main/data/workspace/path/edition.cljs b/frontend/src/app/main/data/workspace/path/edition.cljs index 9f5b3b639..4a93e57dd 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -60,20 +60,20 @@ old-points (->> content upg/content->points) new-points (->> new-content upg/content->points) - point-change (->> (map hash-map old-points new-points) (reduce merge)) + point-change (->> (map hash-map old-points new-points) (reduce merge))] - [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] - - (if (empty? new-content) - (rx/of (dch/commit-changes {:redo-changes rch - :undo-changes uch - :origin it}) - dwc/clear-edition-mode) - (rx/of (dch/commit-changes {:redo-changes rch - :undo-changes uch - :origin it}) - (selection/update-selection point-change) - (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))) + (when (and (some? new-content) (some? shape)) + (let [[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] + (if (empty? new-content) + (rx/of (dch/commit-changes {:redo-changes rch + :undo-changes uch + :origin it}) + dwc/clear-edition-mode) + (rx/of (dch/commit-changes {:redo-changes rch + :undo-changes uch + :origin it}) + (selection/update-selection point-change) + (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))))) (defn modify-content-point [content {dx :x dy :y} modifiers point] @@ -263,7 +263,8 @@ (streams/drag-stream (rx/concat (->> (streams/move-handler-stream snap-toggled start-point point handler opposite points) - (rx/take-until (->> stream (rx/filter ms/mouse-up?))) + (rx/take-until (->> stream (rx/filter #(or (ms/mouse-up? %) + (streams/finish-edition? %))))) (rx/map (fn [{:keys [x y alt? shift?]}] (let [pos (cond-> (gpt/point x y) diff --git a/frontend/src/app/main/data/workspace/path/streams.cljs b/frontend/src/app/main/data/workspace/path/streams.cljs index 3bf10d31e..f8059c483 100644 --- a/frontend/src/app/main/data/workspace/path/streams.cljs +++ b/frontend/src/app/main/data/workspace/path/streams.cljs @@ -24,6 +24,9 @@ (fn [current] (>= (gpt/distance start current) (/ drag-threshold zoom)))) +(defn finish-edition? [event] + (= (ptk/type event) :app.main.data.workspace.common/clear-edition-mode)) + (defn drag-stream ([to-stream] (drag-stream to-stream (rx/empty))) @@ -31,7 +34,8 @@ ([to-stream not-drag-stream] (let [start @ms/mouse-position zoom (get-in @st/state [:workspace-local :zoom] 1) - mouse-up (->> st/stream (rx/filter #(ms/mouse-up? %))) + mouse-up (->> st/stream (rx/filter #(or (finish-edition? %) + (ms/mouse-up? %)))) position-stream (->> ms/mouse-position diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index ddd2ed3f2..610897cd2 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -33,7 +33,7 @@ selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) points (or points selected-points)] - (when-not (empty? points) + (when (and (not (empty? points)) (some? shape)) (let [new-content (-> (tool-fn (:content shape) points) (ups/close-subpaths)) [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]