0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00

Improve path editor

This commit is contained in:
alonso.torres 2021-05-03 11:04:19 +02:00 committed by Andrey Antukh
parent 1c0822ffb3
commit 2582e87ffa
4 changed files with 46 additions and 8 deletions

View file

@ -18,6 +18,7 @@
(d/export drawing/start-path-from-point)
(d/export drawing/close-path-drag-start)
(d/export drawing/change-edit-mode)
(d/export drawing/reset-last-handler)
;; Edition
(d/export edition/start-move-handler)

View file

@ -359,3 +359,13 @@
(and id (= :move mode)) (rx/of (common/finish-path "change-edit-mode"))
(and id (= :draw mode)) (rx/of (start-draw-mode))
:else (rx/empty))))))
(defn reset-last-handler
[]
(ptk/reify ::reset-last-handler
ptk/UpdateEvent
(update [_ state]
(let [id (st/get-path-id state)]
(-> state
(assoc-in [:workspace-local :edit-path id :prev-handler] nil))))))

View file

@ -40,8 +40,8 @@
:command "p"
:fn #(st/emit! (drp/change-edit-mode :draw))}
:add-node {:tooltip "+"
:command "+"
:add-node {:tooltip (ds/shift "+")
:command "shift++"
:fn #(st/emit! (drp/add-node))}
:delete-node {:tooltip (ds/supr)
@ -88,7 +88,30 @@
:command [(ds/c-mod "shift+z") (ds/c-mod "y")]
:fn #(st/emit! (drp/redo-path))}
;; ZOOM
:increase-zoom {:tooltip "+"
:command "+"
:fn #(st/emit! (dw/increase-zoom nil))}
:decrease-zoom {:tooltip "-"
:command "-"
:fn #(st/emit! (dw/decrease-zoom nil))}
:reset-zoom {:tooltip (ds/shift "0")
:command "shift+0"
:fn #(st/emit! dw/reset-zoom)}
:fit-all {:tooltip (ds/shift "1")
:command "shift+1"
:fn #(st/emit! dw/zoom-to-fit-all)}
:zoom-selected {:tooltip (ds/shift "2")
:command "shift+2"
:fn #(st/emit! dw/zoom-to-selected-shape)}
;; Arrow movement
:move-fast-up {:tooltip (ds/shift ds/up-arrow)
:command "shift+up"
:fn #(st/emit! (drp/move-selected :up true))}

View file

@ -30,12 +30,14 @@
(let [{:keys [x y]} position
on-enter
(fn [event]
(st/emit! (drp/path-pointer-enter position)))
(mf/use-callback
(fn [event]
(st/emit! (drp/path-pointer-enter position))))
on-leave
(fn [event]
(st/emit! (drp/path-pointer-leave position)))
(mf/use-callback
(fn [event]
(st/emit! (drp/path-pointer-leave position))))
on-mouse-down
(fn [event]
@ -48,6 +50,9 @@
(let [shift? (kbd/shift? event)
ctrl? (kbd/ctrl? event)]
(cond
last-p?
(st/emit! (drp/reset-last-handler))
(and (= edit-mode :move) ctrl? (not curve?))
(st/emit! (drp/make-curve position))
@ -81,8 +86,7 @@
:on-mouse-down on-mouse-down
:on-mouse-enter on-enter
:on-mouse-leave on-leave
:style {:pointer-events (when last-p? "none")
:cursor (cond
:style {:cursor (cond
(= edit-mode :draw) cur/pen-node
(= edit-mode :move) cur/pointer-node)
:fill "transparent"}}]]))