Skip to content

Commit 786b495

Browse files
committed
fix shortcuts
1 parent b646bbd commit 786b495

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed
+14-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
(ns components.shortcuts-scenes
22
(:require
33
[portfolio.reagent-18 :refer-macros [defscene]]
4+
[re-frame.core :as rf]
5+
[re-pressed.core :as rp]
6+
[renderer.history.events :as-alias history.e]
47
[renderer.ui :as ui]
58
[renderer.utils.keyboard :as keyb]))
69

10+
(rf/dispatch [::rp/set-keydown-rules keyb/keydown-rules])
11+
712
(defscene single-shortcut
813
:title "Single shortcut"
9-
[:div.toolbar.bg-primary.h-10.p-2
10-
[ui/shortcuts [[{:keyCode (keyb/key-codes "P")
11-
:ctrlKey true
12-
:shiftKey true}]]]])
14+
[:div.toolbar.bg-primary.h-10.p-2.gap-2
15+
"Undo"
16+
[ui/shortcuts [::history.e/undo]]])
1317

1418
(defscene multiple-shortcuts
1519
:title "Multiple shortcuts"
16-
[:div.toolbar.bg-primary.h-10.p-2
17-
[ui/shortcuts [[{:keyCode (keyb/key-codes "P")
18-
:ctrlKey true
19-
:shiftKey true}]
20-
[{:keyCode (keyb/key-codes "ONE")
21-
:altKey true}]]]])
20+
[:div.toolbar.bg-primary.h-10.p-2.gap-2
21+
"Redo"
22+
[ui/shortcuts [::history.e/redo]]])
2223

2324
(defscene no-shortcuts
2425
:title "No shortcuts"
25-
[:div.toolbar.bg-primary.h-10.p-2
26-
[ui/shortcuts []]])
26+
[:div.toolbar.bg-primary.h-10.p-2.gap-2
27+
"Event with no shortcuts"
28+
[ui/shortcuts [:event-id-with-no-shortcut]]])

src/renderer/app/views.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
[ui/icon "file"]
205205
[:button.button-link.text-lg
206206
{:on-click #(rf/dispatch [::document.e/new])} "New"]
207-
[ui/shortcuts @(rf/subscribe [::app.s/event-shortcuts [::document.e/new]])]
207+
[ui/shortcuts [::document.e/new]]
208208

209209
[:span "or"]
210210

@@ -240,7 +240,7 @@
240240
[:button.button-link.text-lg
241241
{:on-click #(rf/dispatch [::document.e/open nil])}
242242
"Open"]
243-
[ui/shortcuts @(rf/subscribe [::app.s/event-shortcuts [::document.e/open nil]])]]
243+
[ui/shortcuts [::document.e/open nil]]]
244244

245245
(when (seq recent-documents)
246246
[:<> [:h2.mb-3.mt-8.text-2xl "Recent"]
@@ -262,7 +262,7 @@
262262
[:button.button-link.text-lg
263263
{:on-click #(rf/dispatch [::dialog.e/cmdk])}
264264
"Command panel"]
265-
[ui/shortcuts @(rf/subscribe [::app.s/event-shortcuts [::dialog.e/cmdk]])]]]
265+
[ui/shortcuts [::dialog.e/cmdk]]]]
266266
[:div.flex.items-center.gap-2
267267
[ui/icon "earth"]
268268
[:button.button-link.text-lg

src/renderer/dialog/views.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
(when icon [ui/icon icon])]
7070
label
7171
[:div.right-slot
72-
[ui/shortcuts @(rf/subscribe [::app.s/event-shortcuts action])]]]))
72+
[ui/shortcuts action]]]))
7373

7474
(defn cmdk-group-inner
7575
[items label]

src/renderer/menubar/views.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@
561561
[ui/icon "checkmark"]]
562562
label
563563
[:div.right-slot
564-
[ui/shortcuts @(rf/subscribe [::app.s/event-shortcuts action])]]])
564+
[ui/shortcuts action]]])
565565

566566
(defmethod menu-item :sub-menu
567567
[{:keys [label items disabled]}]
@@ -603,7 +603,7 @@
603603
:disabled disabled}
604604
label
605605
[:div.right-slot
606-
[ui/shortcuts @(rf/subscribe [::app.s/event-shortcuts action])]]])
606+
[ui/shortcuts action]]])
607607

608608
(defn root-menu
609609
[]

src/renderer/ui.cljs

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
["tailwind-merge" :refer [twMerge]]
2020
[re-frame.core :as rf]
2121
[reagent.core :as ra]
22+
[renderer.app.subs :as-alias app.s]
2223
[renderer.utils.keyboard :as keyb]))
2324

2425
(defn merge-with-class
@@ -74,11 +75,13 @@
7475
(into [:span])))
7576

7677
(defn shortcuts
77-
[v]
78-
(when (seq v)
79-
(->> (map format-shortcut v)
80-
(interpose [:span])
81-
(into [:span.inline-flex.text-muted {:class "gap-1.5"}]))))
78+
[event]
79+
(let [event-shortcuts @(rf/subscribe [::app.s/event-shortcuts event])]
80+
(when (seq event-shortcuts)
81+
(->> event-shortcuts
82+
(map format-shortcut)
83+
(interpose [:span])
84+
(into [:span.inline-flex.text-muted {:class "gap-1.5"}])))))
8285

8386
(defn radio-icon-button
8487
[icon-name active props]

0 commit comments

Comments
 (0)