From 63259b3f921285bd6946c6f82483df5036bf1462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 9 Aug 2021 12:02:20 +0200 Subject: [PATCH] :tada: Add shortut Ctrl+Shift+K to detach instances --- CHANGES.md | 1 + .../app/main/data/workspace/libraries.cljs | 25 +++++++++++++++++++ .../app/main/data/workspace/shortcuts.cljs | 4 +++ .../app/main/ui/workspace/context_menu.cljs | 2 ++ 4 files changed, 32 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4f30db2405..796ae9965e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ - Allow to zoom with ctrl + middle button [Taiga #1428](https://tree.taiga.io/project/penpot/us/1428). - Auto placement of duplicated objects [Taiga #1386](https://tree.taiga.io/project/penpot/us/1386). - Go to a undo step clicking on a history element of the list [Taiga #1374](https://tree.taiga.io/project/penpot/us/1374). +- New shortcut to detach components Ctrl+Shift+K [Taiga #1799](https://tree.taiga.io/project/penpot/us/1799). - Set email inputs to type "email", to aid keyboard entry [Taiga #1921](https://tree.taiga.io/project/penpot/issue/1921). - Use space + mouse drag to pan, instead of only space [Taiga #1800](https://tree.taiga.io/project/penpot/us/1800). diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 77b15d1b9d..4c118b7baa 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -462,6 +462,31 @@ :undo-changes uchanges :origin it})))))) +(def detach-selected-components + (ptk/reify ::detach-selected-components + ptk/WatchEvent + (watch [it state _] + (let [page-id (:current-page-id state) + objects (wsh/lookup-page-objects state page-id) + local-library (dwlh/get-local-file state) + container (cp/get-container page-id :page local-library) + + selected (->> state + (wsh/lookup-selected) + (cp/clean-loops objects)) + + [rchanges uchanges] + (reduce (fn [changes id] + (dwlh/concat-changes + changes + (dwlh/generate-detach-instance id container))) + dwlh/empty-changes + selected)] + + (rx/of (dch/commit-changes {:redo-changes rchanges + :undo-changes uchanges + :origin it})))))) + (defn nav-to-component-file [file-id] (us/assert ::us/uuid file-id) diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 9d8ce96180..69fe842325 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -93,6 +93,10 @@ :command (ds/c-mod "k") :fn #(st/emit! dwl/add-component)} + :detach-component {:tooltip (ds/meta-shift "K") + :command (ds/c-mod "shift+k") + :fn #(st/emit! dwl/detach-selected-components)} + :flip-vertical {:tooltip (ds/shift "V") :command "shift+v" :fn #(st/emit! (dw/flip-vertical-selected))} diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index e493bb5fc5..cd7353c1b6 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -195,6 +195,7 @@ [:* [:& menu-separator] [:& menu-entry {:title (tr "workspace.shape.menu.detach-instance") + :shortcut (sc/get-tooltip :detach-component) :on-click do-detach-component}] [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") :on-click do-reset-component}] @@ -205,6 +206,7 @@ [:* [:& menu-separator] [:& menu-entry {:title (tr "workspace.shape.menu.detach-instance") + :shortcut (sc/get-tooltip :detach-component) :on-click do-detach-component}] [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") :on-click do-reset-component}]