From 040dd735990bccca628b4569e256a60599d94b84 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 13 Apr 2020 14:07:05 +0200 Subject: [PATCH] :bug: Fix text edition. --- frontend/src/uxbox/main/data/workspace.cljs | 4 +- frontend/src/uxbox/main/ui/shapes/common.cljs | 67 +++++++++---------- frontend/src/uxbox/main/ui/shapes/icon.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/image.cljs | 2 +- frontend/src/uxbox/main/ui/shapes/text.cljs | 10 ++- 5 files changed, 44 insertions(+), 41 deletions(-) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 560e28b36..80c445033 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -1832,7 +1832,7 @@ ptk/WatchEvent (watch [_ state stream] (->> stream - (rx/filter #(= % :interrupt)) + (rx/filter interrupt?) (rx/take 1) (rx/map (constantly clear-edition-mode)))))) @@ -2428,7 +2428,7 @@ "ctrl+t" #(st/emit! (select-for-drawing :text)) "ctrl+c" #(st/emit! copy-selected) "ctrl+v" #(st/emit! paste) - "esc" #(st/emit! :interrupt deselect-all) + "escape" #(st/emit! :interrupt deselect-all) "del" #(st/emit! delete-selected) "ctrl+up" #(st/emit! (vertical-order-selected :up)) "ctrl+down" #(st/emit! (vertical-order-selected :down)) diff --git a/frontend/src/uxbox/main/ui/shapes/common.cljs b/frontend/src/uxbox/main/ui/shapes/common.cljs index 3600e803c..b4a4965d2 100644 --- a/frontend/src/uxbox/main/ui/shapes/common.cljs +++ b/frontend/src/uxbox/main/ui/shapes/common.cljs @@ -60,44 +60,43 @@ (rx/of (dw/materialize-frame-displacement frame-id))))))) (defn on-mouse-down - ([event shape] (on-mouse-down event shape nil)) - ([event {:keys [id type] :as shape} kk-tmp] - (let [selected @refs/selected-shapes - selected? (contains? selected id) - drawing? @refs/selected-drawing-tool - button (.-which (.-nativeEvent event))] - (when-not (:blocked shape) - (cond - (not= 1 button) - nil + [event {:keys [id type] :as shape}] + (let [selected @refs/selected-shapes + selected? (contains? selected id) + drawing? @refs/selected-drawing-tool + button (.-which (.-nativeEvent event))] + (when-not (:blocked shape) + (cond + (not= 1 button) + nil - drawing? - nil + drawing? + nil - (= type :frame) - (when selected? - (dom/stop-propagation event) - (st/emit! start-move-frame)) + (= type :frame) + (when selected? + (dom/stop-propagation event) + (st/emit! start-move-frame)) - (and (not selected?) (empty? selected)) - (do - (dom/stop-propagation event) - (st/emit! dw/deselect-all - (dw/select-shape id) - start-move-selected)) + (and (not selected?) (empty? selected)) + (do + (dom/stop-propagation event) + (st/emit! dw/deselect-all + (dw/select-shape id) + start-move-selected)) - (and (not selected?) (not (empty? selected))) - (do - (dom/stop-propagation event) - (if (kbd/shift? event) - (st/emit! (dw/select-shape id)) - (st/emit! dw/deselect-all - (dw/select-shape id) - start-move-selected))) - :else - (do - (dom/stop-propagation event) - (st/emit! start-move-selected))))))) + (and (not selected?) (not (empty? selected))) + (do + (dom/stop-propagation event) + (if (kbd/shift? event) + (st/emit! (dw/select-shape id)) + (st/emit! dw/deselect-all + (dw/select-shape id) + start-move-selected))) + :else + (do + (dom/stop-propagation event) + (st/emit! start-move-selected)))))) (defn on-context-menu diff --git a/frontend/src/uxbox/main/ui/shapes/icon.cljs b/frontend/src/uxbox/main/ui/shapes/icon.cljs index 8ce719157..244e8d9c7 100644 --- a/frontend/src/uxbox/main/ui/shapes/icon.cljs +++ b/frontend/src/uxbox/main/ui/shapes/icon.cljs @@ -23,7 +23,7 @@ [{:keys [shape frame] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape)) - on-mouse-down #(common/on-mouse-down % shape selected)] + on-mouse-down #(common/on-mouse-down % shape)] [:g.shape {:class (when selected? "selected") :on-mouse-down on-mouse-down} [:& icon-shape {:shape (geom/transform-shape frame shape)}]])) diff --git a/frontend/src/uxbox/main/ui/shapes/image.cljs b/frontend/src/uxbox/main/ui/shapes/image.cljs index c9a4cac7f..18a523086 100644 --- a/frontend/src/uxbox/main/ui/shapes/image.cljs +++ b/frontend/src/uxbox/main/ui/shapes/image.cljs @@ -25,7 +25,7 @@ [{:keys [shape frame] :as props}] (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape)) - on-mouse-down #(common/on-mouse-down % shape selected)] + on-mouse-down #(common/on-mouse-down % shape)] [:g.shape {:class (when selected? "selected") :on-mouse-down on-mouse-down} [:& image-shape {:shape (geom/transform-shape frame shape)}]])) diff --git a/frontend/src/uxbox/main/ui/shapes/text.cljs b/frontend/src/uxbox/main/ui/shapes/text.cljs index 43e21f600..95266766f 100644 --- a/frontend/src/uxbox/main/ui/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/shapes/text.cljs @@ -23,12 +23,12 @@ ;; --- Events (defn handle-mouse-down - [event {:keys [id group] :as shape} selected] + [event {:keys [id group] :as shape}] (if (and (not (:blocked shape)) (or @refs/selected-drawing-tool @refs/selected-edition)) (dom/stop-propagation event) - (common/on-mouse-down event shape selected))) + (common/on-mouse-down event shape))) ;; --- Text Wrapper @@ -45,12 +45,16 @@ selected? (and (contains? selected id) (= (count selected) 1)) - on-mouse-down #(common/on-mouse-down % shape) + on-mouse-down #(handle-mouse-down % shape) on-context-menu #(common/on-context-menu % shape) + on-double-click (fn [event] + (dom/stop-propagation event) + (dom/prevent-default event) (when selected? (st/emit! (dw/start-edition-mode (:id shape)))))] + [:g.shape {:on-double-click on-double-click :on-mouse-down on-mouse-down :on-context-menu on-context-menu}