0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

🐛 Fix problem with enter to edit paths

This commit is contained in:
alonso.torres 2021-03-26 15:33:55 +01:00 committed by Andrés Moya
parent 7c21624e09
commit 3cb9470db2
6 changed files with 59 additions and 52 deletions

View file

@ -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

View file

@ -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)])))

View file

@ -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)))
(let [objects (lookup-page-objects state)]
(->> stream
(rx/filter interrupt?)
(rx/take 1)
(rx/map (constantly clear-edition-mode))))))))
(rx/map (constantly clear-edition-mode)))))))
(def clear-edition-mode
(ptk/reify ::clear-edition-mode

View file

@ -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))
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)
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}))))))
(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))))))))

View file

@ -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)

View file

@ -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