0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 08:11:30 -05:00

Improved actions locking for better user experience.

This commit is contained in:
Andrey Antukh 2016-02-27 14:10:18 +02:00
parent 94e22902f0
commit 2a0918a567
4 changed files with 24 additions and 13 deletions

View file

@ -5,9 +5,17 @@
;; Actions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defonce actions-lock (atom :nothing))
(defonce actions-s (rx/bus))
(defn emit-action!
(defn acquire-action!
[type]
(rx/push! actions-s type))
(when-let [result (compare-and-set! actions-lock :nothing type)]
;; (println "acquire-action!" type)
(rx/push! actions-s type)))
(defn release-action!
[type]
(when-let [result (compare-and-set! actions-lock type :nothing)]
;; (println "release-action!" type)
(rx/push! actions-s :nothing)))

View file

@ -38,7 +38,7 @@
(and (not selected?) (empty? selected))
(do
(dom/stop-propagation event)
(uuc/emit-action! :shape/movement)
(uuc/acquire-action! :shape/movement)
(rs/emit! (dw/select-shape id)))
(and (not selected?) (not (empty? selected)))
@ -52,7 +52,7 @@
:else
(do
(dom/stop-propagation event)
(uuc/emit-action! :shape/movement))))))
(uuc/acquire-action! :shape/movement))))))
(defn on-mouse-up
[event {:keys [id group] :as shape}]
@ -63,7 +63,7 @@
:else
(do
(dom/stop-propagation event)
(uuc/emit-action! :nothing))))
(uuc/release-action! :shape/movement))))
(declare handlers)

View file

@ -31,7 +31,7 @@
(and (not selected?) (empty? selected))
(do
(dom/stop-propagation event)
(uuc/emit-action! :shape/movement)
(uuc/acquire-action! :shape/movement)
(rs/emit! (dw/select-shape id)))
(and (not selected?) (not (empty? selected)))
@ -45,7 +45,7 @@
:else
(do
(dom/stop-propagation event)
(uuc/emit-action! :shape/movement))))))
(uuc/acquire-action! :shape/movement))))))
(defn on-mouse-up
[event {:keys [id group] :as shape}]
@ -56,7 +56,7 @@
:else
(do
(dom/stop-propagation event)
(uuc/emit-action! :nothing))))
(uuc/release-action! :shape/movement))))
(defn- text-component-did-mount
[own]
@ -64,12 +64,14 @@
(let [container (mx/get-ref-dom own "container")
local (:rum/local own)]
(swap! local assoc :edition true)
(uuc/acquire-action! ::edition)
(set! (.-contentEditable container) true)
(.setAttribute container "contenteditable" "true")
(.focus container)))
(on-blur [ev]
(let [container (mx/get-ref-dom own "container")
local (:rum/local own)]
(uuc/release-action! ::edition)
(swap! local assoc :edition false)
(set! (.-contentEditable container) false)
(.removeAttribute container "contenteditable")))]

View file

@ -84,11 +84,12 @@
(when-not (empty? (:selected workspace))
(rs/emit! (dw/deselect-all)))
(if-let [shape (:drawing workspace)]
(uuc/emit-action! :draw/shape)
(uuc/emit-action! :draw/selrect)))
(uuc/acquire-action! :draw/shape)
(uuc/acquire-action! :draw/selrect)))
(on-mouse-up [event]
(dom/stop-propagation event)
(uuc/emit-action! :nothing))]
(uuc/release-action! :draw/shape)
(uuc/release-action! :draw/selrect))]
(html
[:svg.viewport {:width uuwb/viewport-width
:height uuwb/viewport-height
@ -124,11 +125,11 @@
(on-key-down [event]
(when (kbd/space? event)
(uuc/emit-action! :scroll/viewport)))
(uuc/acquire-action! :scroll/viewport)))
(on-key-up [event]
(when (kbd/space? event)
(uuc/emit-action! :nothing)))
(uuc/release-action! :scroll/viewport)))
(on-mousemove [event]
(let [wpt (gpt/point (.-clientX event)