🐛 Fix some problems with paths

This commit is contained in:
alonso.torres 2021-05-27 10:33:23 +02:00 committed by Andrey Antukh
parent 96d9e101cc
commit f8f506a8be
4 changed files with 25 additions and 20 deletions

View file

@ -88,10 +88,10 @@
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
page-id (:current-page-id state) page-id (:current-page-id state)
id (get-in state [:workspace-local :edition]) id (get-in state [:workspace-local :edition])
old-content (get-in state [:workspace-local :edit-path id :old-content])] old-content (get-in state [:workspace-local :edit-path id :old-content])
(if (some? old-content) shape (get-in state (st/get-path state))]
(let [shape (get-in state (st/get-path state)) (if (and (some? old-content) (some? shape))
[rch uch] (generate-path-changes objects page-id shape old-content (:content shape))] (let [[rch uch] (generate-path-changes objects page-id shape old-content (:content shape))]
(rx/of (dch/commit-changes {:redo-changes rch (rx/of (dch/commit-changes {:redo-changes rch
:undo-changes uch :undo-changes uch
:origin it}))) :origin it})))

View file

@ -60,10 +60,10 @@
old-points (->> content upg/content->points) old-points (->> content upg/content->points)
new-points (->> new-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)]
(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) (if (empty? new-content)
(rx/of (dch/commit-changes {:redo-changes rch (rx/of (dch/commit-changes {:redo-changes rch
:undo-changes uch :undo-changes uch
@ -73,7 +73,7 @@
:undo-changes uch :undo-changes uch
:origin it}) :origin it})
(selection/update-selection point-change) (selection/update-selection point-change)
(fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))) (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler))))))))))
(defn modify-content-point (defn modify-content-point
[content {dx :x dy :y} modifiers point] [content {dx :x dy :y} modifiers point]
@ -263,7 +263,8 @@
(streams/drag-stream (streams/drag-stream
(rx/concat (rx/concat
(->> (streams/move-handler-stream snap-toggled start-point point handler opposite points) (->> (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 (rx/map
(fn [{:keys [x y alt? shift?]}] (fn [{:keys [x y alt? shift?]}]
(let [pos (cond-> (gpt/point x y) (let [pos (cond-> (gpt/point x y)

View file

@ -24,6 +24,9 @@
(fn [current] (fn [current]
(>= (gpt/distance start current) (/ drag-threshold zoom)))) (>= (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 (defn drag-stream
([to-stream] ([to-stream]
(drag-stream to-stream (rx/empty))) (drag-stream to-stream (rx/empty)))
@ -31,7 +34,8 @@
([to-stream not-drag-stream] ([to-stream not-drag-stream]
(let [start @ms/mouse-position (let [start @ms/mouse-position
zoom (get-in @st/state [:workspace-local :zoom] 1) 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 position-stream
(->> ms/mouse-position (->> ms/mouse-position

View file

@ -33,7 +33,7 @@
selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{})
points (or points 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) (let [new-content (-> (tool-fn (:content shape) points)
(ups/close-subpaths)) (ups/close-subpaths))
[rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)]