From 6d427cdc9cb0218968d1413d26ed02cac568da4a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 9 Mar 2021 17:50:22 +0100 Subject: [PATCH] :bug: Fix issues with Alt key in distance measurement --- CHANGES.md | 1 + frontend/src/app/main/data/shortcuts.cljs | 6 +++--- frontend/src/app/main/data/workspace.cljs | 7 +++++++ frontend/src/app/main/data/workspace/shortcuts.cljs | 10 ++++++++++ frontend/src/app/main/refs.cljs | 3 ++- frontend/src/app/main/ui/workspace/viewport.cljs | 5 +++-- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 23b3a3884..915473acf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ - Fix issue with typographies panel cannot be collapsed [#707](https://github.com/penpot/penpot/issues/707) - Fix problem with middle mouse button press moving the canvas when not moving mouse [#717](https://github.com/penpot/penpot/issues/717) - Fix problem with masks interactions outside bounds [#718](https://github.com/penpot/penpot/issues/718) +- Fix issues with Alt key in distance measurement [#672](https://github.com/penpot/penpot/issues/672) ### :heart: Community contributions by (Thank you!) diff --git a/frontend/src/app/main/data/shortcuts.cljs b/frontend/src/app/main/data/shortcuts.cljs index 36b77b32d..f8ff70f3b 100644 --- a/frontend/src/app/main/data/shortcuts.cljs +++ b/frontend/src/app/main/data/shortcuts.cljs @@ -50,12 +50,12 @@ (c-mod (a-mod shortcut))) (defn bind-shortcuts [shortcuts bind-fn cb-fn] - (doseq [[key {:keys [command disabled fn]}] shortcuts] + (doseq [[key {:keys [command disabled fn type]}] shortcuts] (when-not disabled (if (vector? command) (doseq [cmd (seq command)] - (bind-fn cmd (cb-fn key fn))) - (bind-fn command (cb-fn key fn)))))) + (bind-fn cmd (cb-fn key fn) type)) + (bind-fn command (cb-fn key fn) type))))) (defn meta [key] (str diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 3c4243ee0..8ea1041d4 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1726,6 +1726,13 @@ :data [image]}] (rx/of (dwp/upload-media-workspace params @ms/mouse-position)))))) +(defn toggle-distances-display [value] + (ptk/reify ::toggle-distances-display + + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-local :show-distances?] value)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interactions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 9a2302ee3..f9ca932b4 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -260,6 +260,16 @@ :start-editing {:tooltip (ds/enter) :command "enter" :fn #(st/emit! (dw/start-editing-selected))} + + :start-measure {:tooltip (ds/alt "") + :command ["alt" "."] + :type "keydown" + :fn #(st/emit! (dw/toggle-distances-display true))} + + :stop-measure {:tooltip (ds/alt "") + :command ["alt" "."] + :type "keyup" + :fn #(st/emit! (dw/toggle-distances-display false))} }) (defn get-tooltip [shortcut] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index f2bf529bb..b2ed9e41f 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -69,7 +69,8 @@ :transform :hover :modifiers - :selrect]) + :selrect + :show-distances?]) workspace-local =)) (def selected-zoom diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 24d48a6b7..eeaaa55d1 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -350,7 +350,8 @@ transform hover modifiers - selrect]} local + selrect + show-distances?]} local page-id (mf/use-ctx ctx/current-page-id) @@ -797,7 +798,7 @@ [:& selection-handlers {:selected selected :zoom zoom :edition edition - :show-distances (and (not transform) @alt?) + :show-distances (and (not transform) show-distances?) :disable-handlers (or drawing-tool edition)}]) (when (= (count selected) 1)