From d86dc608b064401d480d9f9ebf34c3ca48ac1dae Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 12 Feb 2021 12:12:39 +0100 Subject: [PATCH] :sparkles: Adds edition shortcut and context menu item --- CHANGES.md | 3 ++- frontend/resources/locales.json | 6 +++++ frontend/src/app/main/data/shortcuts.cljs | 5 ++++ frontend/src/app/main/data/workspace.cljs | 25 +++++++++++++++++++ .../app/main/data/workspace/shortcuts.cljs | 7 +++++- .../app/main/ui/workspace/context_menu.cljs | 21 +++++++++++++--- .../main/ui/workspace/shapes/text/editor.cljs | 8 +++--- 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b51985f55..c740b6d96 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,8 @@ ### New features - Bounce & Complaint handling. - +- Disable groups interactions when holding "Ctrl" key (deep selection) +- New action in context menu to "edit" some shapes (binded to key "Enter") ### Bugs fixed diff --git a/frontend/resources/locales.json b/frontend/resources/locales.json index 322c7bd72..b16baae2f 100644 --- a/frontend/resources/locales.json +++ b/frontend/resources/locales.json @@ -4841,5 +4841,11 @@ "en" : "Flip vertical", "es" : "Voltear vertical" } + }, + "workspace.shape.menu.edit" : { + "translations" : { + "en" : "Edit", + "es" : "Editar" + } } } diff --git a/frontend/src/app/main/data/shortcuts.cljs b/frontend/src/app/main/data/shortcuts.cljs index 48afb5ae5..03800e992 100644 --- a/frontend/src/app/main/data/shortcuts.cljs +++ b/frontend/src/app/main/data/shortcuts.cljs @@ -24,6 +24,7 @@ (def mac-shift "\u21E7") (def mac-control "\u2303") (def mac-esc "\u238B") +(def mac-enter "\u23CE") (def left-arrow "\u2190") (def up-arrow "\u2191") @@ -73,3 +74,7 @@ mac-esc "Escape")) +(defn enter [] + (if (cfg/check-platform? :macos) + mac-enter + "Enter")) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 79d370c33..ab4cb2101 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1089,6 +1089,31 @@ (rx/of (relocate-shapes selected parent-id to-index)))))) +(defn start-editing-selected + [] + (ptk/reify ::start-editing-selected + ptk/WatchEvent + (watch [_ state stream] + (let [selected (get-in state [:workspace-local :selected])] + (if-not (= 1 (count selected)) + (rx/empty) + + (let [objects (dwc/lookup-page-objects state) + {:keys [id type shapes]} (get objects (first selected))] + + (case type + :text + (rx/of (dwc/start-edition-mode id)) + + :group + (rx/of (dwc/select-shapes (into (d/ordered-set) [(last shapes)]))) + + :path + (rx/of (dwc/start-edition-mode id) + (dwdp/start-path-edit id)) + :else (rx/empty)))))))) + + ;; --- Change Page Order (D&D Ordering) (defn relocate-page diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 2eda58376..33100459d 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -255,7 +255,12 @@ :escape {:tooltip (ds/esc) :command "escape" - :fn #(st/emit! (esc-pressed))}}) + :fn #(st/emit! (esc-pressed))} + + :start-editing {:tooltip (ds/enter) + :command "enter" + :fn #(st/emit! (dw/start-editing-selected))} + }) (defn get-tooltip [shortcut] (assert (contains? shortcuts shortcut) (str shortcut)) diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 01c1151d0..7d6c99610 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -24,6 +24,7 @@ [app.main.ui.icons :as i] [app.util.dom :as dom] [app.util.i18n :refer [t] :as i18n] + [app.util.timers :as timers] [beicon.core :as rx] [okulary.core :as l] [potok.core :as ptk] @@ -53,6 +54,10 @@ {:keys [id] :as shape} (:shape mdata) selected (:selected mdata) + single? (= (count selected) 1) + multiple? (> (count selected) 1) + editable-shape? (#{:group :text :path} (:type shape)) + current-file-id (mf/use-ctx ctx/current-file-id) do-duplicate (st/emitf dw/duplicate-selected) @@ -77,6 +82,9 @@ do-add-component (st/emitf dwl/add-component) do-detach-component (st/emitf (dwl/detach-component id)) do-reset-component (st/emitf (dwl/reset-component id)) + do-start-editing (fn [] + ;; We defer the execution so the mouse event won't close the editor + (timers/schedule #(st/emit! (dw/start-editing-selected)))) do-update-component (st/emitf (dwc/start-undo-transaction) (dwl/update-component id) @@ -99,7 +107,7 @@ :on-accept confirm-update-remote-component})) do-show-component (st/emitf (dw/go-to-layout :assets)) do-navigate-component-file (st/emitf (dwl/nav-to-component-file - (:component-file shape)))] + (:component-file shape)))] [:* [:& menu-entry {:title (t locale "workspace.shape.menu.copy") :shortcut (sc/get-tooltip :copy) @@ -128,7 +136,7 @@ :on-click do-send-to-back}] [:& menu-separator] - (when (> (count selected) 1) + (when multiple? [:* [:& menu-entry {:title (t locale "workspace.shape.menu.group") :shortcut (sc/get-tooltip :group) @@ -138,7 +146,7 @@ :on-click do-mask-group}] [:& menu-separator]]) - (when (>= (count selected) 1) + (when (or single? multiple?) [:* [:& menu-entry {:title (t locale "workspace.shape.menu.flip-vertical") :shortcut (sc/get-tooltip :flip-vertical) @@ -148,7 +156,7 @@ :on-click do-flip-horizontal}] [:& menu-separator]]) - (when (and (= (count selected) 1) (= (:type shape) :group)) + (when (and single? (= (:type shape) :group)) [:* [:& menu-entry {:title (t locale "workspace.shape.menu.ungroup") :shortcut (sc/get-tooltip :ungroup) @@ -161,6 +169,11 @@ :shortcut (sc/get-tooltip :group) :on-click do-mask-group}])]) + (when (and single? editable-shape?) + [:& menu-entry {:title (t locale "workspace.shape.menu.edit") + :shortcut (sc/get-tooltip :start-editing) + :on-click do-start-editing}]) + (if (:hidden shape) [:& menu-entry {:title (t locale "workspace.shape.menu.show") :on-click do-show-shape}] diff --git a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs index d279c16fa..c1b638ed0 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs @@ -182,11 +182,9 @@ (and self (.contains self target)) (and cpicker (.contains cpicker target)) (and palette (.contains palette target))) - (do - - (if selecting? - (mf/set-ref-val! selecting-ref false) - (on-close)))))) + (if selecting? + (mf/set-ref-val! selecting-ref false) + (on-close))))) on-mouse-down (fn [event]