From 3cb9470db20b563122623dc2d1404d1a3d2cdff5 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 26 Mar 2021 15:33:55 +0100 Subject: [PATCH] :bug: Fix problem with enter to edit paths --- CHANGES.md | 1 + frontend/src/app/main/data/workspace.cljs | 6 ++- .../src/app/main/data/workspace/common.cljs | 41 ++------------- .../app/main/data/workspace/drawing/path.cljs | 52 +++++++++++++++---- .../src/app/main/ui/workspace/viewport.cljs | 2 +- .../main/ui/workspace/viewport/actions.cljs | 9 ++-- 6 files changed, 59 insertions(+), 52 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 20f76d437..e42430339 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -53,6 +53,7 @@ - Updates worksans font [#744](https://github.com/penpot/penpot/issues/744) - Fix problem with team management in dashboard [Taiga #1475](https://tree.taiga.io/project/penpot/issue/1475) - Fix problem with blending modes in masks [Taiga #1476](https://tree.taiga.io/project/penpot/issue/1476) +- Fix problem with enter to edit paths [Taiga #1481](https://tree.taiga.io/project/penpot/issue/1481) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 61b51eebb..6b2472f92 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1015,9 +1015,13 @@ {:keys [id type shapes]} (get objects (first selected))] (case type - (:text :path) + :text (rx/of (dwc/start-edition-mode id)) + :path + (rx/of (dwc/start-edition-mode id) + (dwdp/start-path-edit id)) + :group (rx/of (dwc/select-shapes (into (d/ordered-set) [(last shapes)]))) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index 808ed5259..c767a5251 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -517,33 +517,6 @@ objects (lookup-page-objects state page-id)] (rx/of (expand-all-parents ids objects)))))) -;; --- Start shape "edition mode" -(defn stop-path-edit [] - (ptk/reify ::stop-path-edit - ptk/UpdateEvent - (update [_ state] - (let [id (get-in state [:workspace-local :edition])] - (update state :workspace-local dissoc :edit-path id))))) - -(defn start-path-edit - [id] - (ptk/reify ::start-path-edit - ptk/UpdateEvent - (update [_ state] - ;; Only edit if the object has been created - (if-let [id (get-in state [:workspace-local :edition])] - (assoc-in state [:workspace-local :edit-path id] {:edit-mode :move - :selected #{} - :snap-toggled true}) - state)) - - ptk/WatchEvent - (watch [_ state stream] - (->> stream - (rx/filter #(= % :interrupt)) - (rx/take 1) - (rx/map #(stop-path-edit)))))) - (declare clear-edition-mode) (defn start-edition-mode @@ -562,15 +535,11 @@ ptk/WatchEvent (watch [_ state stream] - (let [objects (lookup-page-objects state) - path? (= :path (get-in objects [id :type]))] - (rx/merge - (when path? - (rx/of (start-path-edit id))) - (->> stream - (rx/filter interrupt?) - (rx/take 1) - (rx/map (constantly clear-edition-mode)))))))) + (let [objects (lookup-page-objects state)] + (->> stream + (rx/filter interrupt?) + (rx/take 1) + (rx/map (constantly clear-edition-mode))))))) (def clear-edition-mode (ptk/reify ::clear-edition-mode diff --git a/frontend/src/app/main/data/workspace/drawing/path.cljs b/frontend/src/app/main/data/workspace/drawing/path.cljs index 4f23b1c3e..71b2265a2 100644 --- a/frontend/src/app/main/data/workspace/drawing/path.cljs +++ b/frontend/src/app/main/data/workspace/drawing/path.cljs @@ -180,11 +180,7 @@ (or (= (ptk/type event) ::finish-path) (= (ptk/type event) :esc-pressed) (= event :interrupt) ;; ESC - (and (ms/mouse-double-click? event)) - (and (ms/keyboard-event? event) - (= type :down) - ;; TODO: Enter now finish path but can finish drawing/editing as well - (= enter-keycode (:key event))))) + (and (ms/mouse-double-click? event)))) (defn generate-path-changes [page-id shape old-content new-content] (us/verify ::content old-content) @@ -572,11 +568,13 @@ ptk/WatchEvent (watch [_ state stream] (let [id (get-in state [:workspace-local :edition]) - shape (get-in state (get-path state)) - page-id (:current-page-id state) - old-content (get-in state [:workspace-local :edit-path id :old-content]) - [rch uch] (generate-path-changes page-id shape old-content (:content shape))] - (rx/of (dwc/commit-changes rch uch {:commit-local? true})))))) + old-content (get-in state [:workspace-local :edit-path id :old-content])] + (if (some? old-content) + (let [shape (get-in state (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)))))) (declare start-draw-mode) (defn check-changed-content [] @@ -829,3 +827,37 @@ (rx/take 1) (rx/observe-on :async) (rx/map #(handle-new-shape-result shape-id)))))))) + +(defn stop-path-edit [] + (ptk/reify ::stop-path-edit + ptk/UpdateEvent + (update [_ state] + (let [id (get-in state [:workspace-local :edition])] + (update state :workspace-local dissoc :edit-path id))))) + +(defn start-path-edit + [id] + (ptk/reify ::start-path-edit + ptk/UpdateEvent + (update [_ state] + (let [edit-path (get-in state [:workspace-local :edit-path id])] + + (cond-> state + (or (not edit-path) (= :draw (:edit-mode edit-path))) + (assoc-in [:workspace-local :edit-path id] {:edit-mode :move + :selected #{} + :snap-toggled true}) + + (and (some? edit-path) (= :move (:edit-mode edit-path))) + (assoc-in [:workspace-local :edit-path id :edit-mode] :draw)))) + + ptk/WatchEvent + (watch [_ state stream] + (let [mode (get-in state [:workspace-local :edit-path id :edit-mode])] + (rx/concat + (rx/of (change-edit-mode mode)) + (->> stream + (rx/take-until (->> stream (rx/filter (ptk/type? ::start-path-edit)))) + (rx/filter #(= % :interrupt)) + (rx/take 1) + (rx/map #(stop-path-edit)))))))) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 04849970d..0727298a7 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -91,7 +91,7 @@ on-click (actions/on-click hover selected) on-context-menu (actions/on-context-menu hover) - on-double-click (actions/on-double-click hover hover-ids objects) + on-double-click (actions/on-double-click hover hover-ids drawing-path? objects) on-drag-enter (actions/on-drag-enter) on-drag-over (actions/on-drag-over) on-drop (actions/on-drop file viewport-ref zoom) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index 2c4c29a39..19fe7b742 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -135,9 +135,9 @@ (st/emit! (dw/select-shape (:id @hover)))))))) (defn on-double-click - [hover hover-ids objects] + [hover hover-ids drawing-path? objects] (mf/use-callback - (mf/deps @hover @hover-ids) + (mf/deps @hover @hover-ids drawing-path?) (fn [event] (dom/stop-propagation event) (let [ctrl? (kbd/ctrl? event) @@ -153,7 +153,7 @@ (st/emit! (ms/->MouseEvent :double-click ctrl? shift? alt?)) - (when shape + (when (and (not drawing-path?) shape) (cond frame? (st/emit! (dw/select-shape id shift?)) @@ -164,7 +164,8 @@ (st/emit! (dw/select-shape (:id selected)))) (or text? path?) - (st/emit! (dw/start-edition-mode id)) + (st/emit! (dw/select-shape id) + (dw/start-editing-selected)) :else ;; Do nothing