Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(ux): keymap manager for plugins #9430

Merged
merged 33 commits into from Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
602e023
enhance(ux): support the keymap manager within modal container
xyhp915 May 5, 2023
39f529b
enhance(ui): layout of the recording shortcut modal
xyhp915 May 5, 2023
9f36b74
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 5, 2023
5f3f20e
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 8, 2023
c4c9be9
fix(plugin): normalize plugin keybindings to adapt for the closure li…
xyhp915 May 8, 2023
867dd8f
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 9, 2023
535f64b
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 10, 2023
df578a4
fix(shortcuts): incorrect validation for removing shortcut
xyhp915 May 10, 2023
e195272
enhance(ux): shortcut recorder actions impl
xyhp915 May 10, 2023
c33aa2c
fix(shortcuts): restore all shortcuts when the shortcuts recorder closed
xyhp915 May 10, 2023
6bed032
refactor: rename install-shortcut! with more semantic
xyhp915 May 10, 2023
0e70f02
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 11, 2023
82c36b7
enhance(shortcuts): plugins shortcuts tables
xyhp915 May 11, 2023
b791a9c
enhance(ui): active state for shortcut table fold marker
xyhp915 May 11, 2023
cbeccfb
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 15, 2023
be94f68
enhance(shortcuts): list plugins shortcuts in keymaps manage pane
xyhp915 May 15, 2023
7d5f4e6
enhance(shortcuts): expose shortcut cmd map from the pallette cmd to …
xyhp915 May 15, 2023
c255d16
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 15, 2023
a686517
fix(shortcuts): action name of the custom editing shortcut for plugin…
xyhp915 May 15, 2023
72b6f7e
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 16, 2023
414ff11
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 17, 2023
58c051c
enhance(ui): polish style of keymap modal
xyhp915 May 18, 2023
b6a7b81
enhance(shortcuts): polish list for the plugins shortcuts
xyhp915 May 18, 2023
0dea777
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 19, 2023
87907c7
fix(shortcuts): conflicts
xyhp915 May 19, 2023
596cdaf
fix: lint
xyhp915 May 19, 2023
f4de083
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 23, 2023
b25d4db
Merge branch 'master' into enhance/keymaps-manager-x
logseq-cldwalker May 25, 2023
dded021
Merge branch 'master' into enhance/keymaps-manager-x
logseq-cldwalker May 25, 2023
92a94c6
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 May 28, 2023
f1ba83b
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 Jun 5, 2023
39297d5
Merge branch 'master' into enhance/keymaps-manager-x
xyhp915 Jun 8, 2023
53612c5
Merge branch 'master' into enhance/keymaps-manager-x
logseq-cldwalker Jun 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/frontend/components/right_sidebar.cljs
Expand Up @@ -56,7 +56,7 @@
(rum/defc shortcut-settings
[]
[:div.contents.flex-col.flex.ml-3
(shortcut/shortcut {:show-title? false})])
(shortcut/shortcut-page {:show-title? false})])

(defn- block-with-breadcrumb
[repo block idx sidebar-key ref?]
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/components/settings.css
Expand Up @@ -2,8 +2,7 @@

&-main {
> header {
padding: 10px;
padding-top: 0;
padding: 0 10px 10px;
border-bottom: 1px solid var(--ls-quaternary-background-color);

h1 {
Expand Down
134 changes: 90 additions & 44 deletions src/main/frontend/components/shortcut.cljs
Expand Up @@ -13,39 +13,46 @@

(rum/defcs customize-shortcut-dialog-inner <
(rum/local "")
(rum/local nil :rum/action)
(shortcut/record!)
[state k action-name current-binding]
(let [keypress (:rum/local state)
keyboard-shortcut (if (= "" @keypress) current-binding @keypress)]
[:div
[:div
(let [*keypress (:rum/local state)
*action (:rum/action state)
keypressed? (not= "" @*keypress)
keyboard-shortcut (if-not keypressed? current-binding @*keypress)]
[:<>
[:div.sm:w-lsm
[:p.mb-4 "Press any sequence of keys to set the shortcut for the " [:b action-name] " action."]
[:p.mb-4.mt-4
(ui/render-keyboard-shortcut (-> keyboard-shortcut
(str/trim)
(str/lower-case)
(str/split #" |\+")))
" "
[:a.text-sm
{:style {:margin-left "12px"}
:on-click (fn []
(dh/remove-shortcut k)
(shortcut/refresh!)
(swap! keypress (fn [] "")) ;; Clear local state
)}
"Reset"]]]
(when keypressed?
[:a.text-sm
{:style {:margin-left "12px"}
:on-click (fn []
(dh/remove-shortcut k)
(shortcut/refresh!)
(swap! *keypress (fn [] "")) ;; Clear local state
)}
"Reset"])]]
[:div.cancel-save-buttons.text-right.mt-4
(ui/button "Save" :on-click state/close-modal!)
(ui/button "Save" :on-click (fn []
(reset! *action :save)
(state/close-modal!)))
[:a.ml-4
{:on-click (fn []
(reset! keypress (dh/binding-for-storage current-binding))
(reset! *keypress (dh/binding-for-storage current-binding))
(reset! *action :cancel)
(state/close-modal!))} "Cancel"]]]))

(defn customize-shortcut-dialog [k action-name displayed-binding]
(fn [_]
(customize-shortcut-dialog-inner k action-name displayed-binding)))

(rum/defc shortcut-col [k binding configurable? action-name]
(rum/defc shortcut-col [_category k binding configurable? action-name]
(let [conflict? (dh/potential-conflict? k)
displayed-binding (dh/binding-for-display k binding)
disabled? (str/includes? displayed-binding "system default")]
Expand All @@ -61,28 +68,48 @@
(if disabled? "Cannot override system default" "Click to modify"))
:background (if conflict? "pink" (when disabled? "gray"))
:on-click (when-not disabled?
#(state/set-modal! (customize-shortcut-dialog k action-name displayed-binding))))])))

(rum/defc shortcut-table < rum/reactive
([name]
(shortcut-table name false))
([name configurable?]
(let [shortcut-config (rum/cursor-in
state/state
[:config (state/get-current-repo) :shortcuts])
_ (rum/react shortcut-config)]
[:div
[:table
[:thead
[:tr
[:th.text-left [:b (t name)]]
[:th.text-right]]]
[:tbody
(map (fn [[k {:keys [binding]}]]
[:tr {:key (str k)}
[:td.text-left (t (dh/decorate-namespace k))]
(shortcut-col k binding configurable? (t (dh/decorate-namespace k)))])
(dh/binding-by-category name))]]])))
#(state/set-sub-modal!
(customize-shortcut-dialog k action-name displayed-binding)
{:center? true})))])))

(rum/defcs shortcut-table
< rum/reactive
(rum/local true ::folded?)
{:will-mount (fn [state]
(let [name (first (:rum/args state))]
(cond-> state
(contains? #{:shortcut.category/basics}
name)
(-> ::folded? (reset! false) (do state)))))}
[state category configurable?]
(let [*folded? (::folded? state)
plugin? (= category :shortcut.category/plugins)
_ (state/sub [:config (state/get-current-repo) :shortcuts])]
[:div.cp__shortcut-table-wrap
[:a.fold
logseq-cldwalker marked this conversation as resolved.
Show resolved Hide resolved
{:on-click #(reset! *folded? (not @*folded?))}
(ui/icon (if @*folded? "chevron-left" "chevron-down"))]
[:table
[:thead
[:tr
[:th.text-left [:b (t category)]]
[:th.text-right]]]
(when-not @*folded?
[:tbody
(map (fn [[k {:keys [binding]}]]
(let [cmd (dh/shortcut-cmd k)
label (cond
(string? (:desc cmd))
[:<>
[:code.text-xs (namespace k)]
[:small.pl-1 (:desc cmd)]]

(not plugin?) (-> k (dh/decorate-namespace) (t))
:else (str k))]
[:tr {:key (str k)}
[:td.text-left.flex.items-center label]
(shortcut-col category k binding configurable? label)]))
(dh/binding-by-category category))])]]))

(rum/defc trigger-table []
[:table
Expand Down Expand Up @@ -167,13 +194,9 @@
[:td.text-right (get rendered name)]])
list)]]))

(rum/defc shortcut
[{:keys [show-title?]
:or {show-title? true}}]
[:div
(when show-title? [:h1.title (t :help/shortcut-page-title)])
(trigger-table)
(markdown-and-orgmode-syntax)
(rum/defc keymap-tables
[]
[:div.cp__keymap-tables
(shortcut-table :shortcut.category/basics true)
(shortcut-table :shortcut.category/navigating true)
(shortcut-table :shortcut.category/block-editing true)
Expand All @@ -182,4 +205,27 @@
(shortcut-table :shortcut.category/formatting true)
(shortcut-table :shortcut.category/toggle true)
(when (state/enable-whiteboards?) (shortcut-table :shortcut.category/whiteboard true))
(shortcut-table :shortcut.category/plugins true)
(shortcut-table :shortcut.category/others true)])

(rum/defc keymap-pane
[]
(let [[ready?, set-ready!] (rum/use-state false)]
(rum/use-effect!
(fn [] (js/setTimeout #(set-ready! true) 32))
[])

[:div.cp__keymap-pane
[:h1.pb-2.text-3xl.pt-2 "Keymap"]
(if ready?
(keymap-tables)
[:p.flex.justify-center.py-20 (ui/loading "")])]))

(rum/defc shortcut-page
[{:keys [show-title?]
:or {show-title? true}}]
[:div.cp__shortcut-page
(when show-title? [:h1.title (t :help/shortcut-page-title)])
(trigger-table)
(markdown-and-orgmode-syntax)
(keymap-tables)])
28 changes: 28 additions & 0 deletions src/main/frontend/components/shortcut.css
@@ -0,0 +1,28 @@
.ui__modal {
&[label="keymap-manager"] {
.panel-content {
@apply m-[-16px];
}

@screen lg {
.panel-content {
width: 980px;
}
}
}
}

.cp__shortcut {
&-table-wrap {
@apply relative;

a.fold {
@apply absolute right-0 top-0 w-full pt-3 pr-3
pb-3 flex items-center justify-end select-none;

&:active {
@apply bg-white/50 opacity-60;
}
}
}
}
6 changes: 6 additions & 0 deletions src/main/frontend/handler/events.cljs
Expand Up @@ -23,6 +23,7 @@
[frontend.components.shell :as shell]
[frontend.components.whiteboard :as whiteboard]
[frontend.components.user.login :as login]
[frontend.components.shortcut :as shortcut]
[frontend.config :as config]
[frontend.context.i18n :refer [t]]
[frontend.db :as db]
Expand Down Expand Up @@ -940,6 +941,11 @@
(defmethod handle :editor/quick-capture [[_ args]]
(quick-capture/quick-capture args))

(defmethod handle :modal/keymap-manager [[_]]
(state/set-modal!
#(shortcut/keymap-pane)
{:label "keymap-manager"}))

(defmethod handle :editor/toggle-own-number-list [[_ blocks]]
(let [batch? (sequential? blocks)
blocks (cond->> blocks
Expand Down
5 changes: 3 additions & 2 deletions src/main/frontend/handler/plugin.cljs
Expand Up @@ -297,9 +297,10 @@
[pid key keybinding]
(let [id (keyword (str "plugin." pid "/" key))
binding (:binding keybinding)
binding (some->> (if (string? binding) [binding] (seq binding))
(map util/normalize-user-keyname))
binding (if util/mac?
(or (:mac keybinding) binding)
binding)
(or (:mac keybinding) binding) binding)
mode (or (:mode keybinding) :global)
mode (get keybinding-mode-handler-map (keyword mode))]
[mode id {:binding binding}]))
Expand Down
25 changes: 16 additions & 9 deletions src/main/frontend/modules/shortcut/config.cljs
Expand Up @@ -113,19 +113,19 @@
:whiteboard/zoom-out {:binding "shift+dash"
:fn #(.zoomOut (.-api ^js (state/active-tldraw-app)) false)}

:whiteboard/zoom-in {:binding "shift+="
:whiteboard/zoom-in {:binding "shift+equals"
logseq-cldwalker marked this conversation as resolved.
Show resolved Hide resolved
:fn #(.zoomIn (.-api ^js (state/active-tldraw-app)) false)}

:whiteboard/send-backward {:binding "["
:whiteboard/send-backward {:binding "open-square-bracket"
:fn #(.sendBackward ^js (state/active-tldraw-app))}

:whiteboard/send-to-back {:binding "shift+["
:whiteboard/send-to-back {:binding "shift+open-square-bracket"
:fn #(.sendToBack ^js (state/active-tldraw-app))}

:whiteboard/bring-forward {:binding "]"
:whiteboard/bring-forward {:binding "close-square-bracket"
:fn #(.bringForward ^js (state/active-tldraw-app))}

:whiteboard/bring-to-front {:binding "shift+]"
:whiteboard/bring-to-front {:binding "shift+close-square-bracket"
:fn #(.bringToFront ^js (state/active-tldraw-app))}

:whiteboard/lock {:binding "mod+l"
Expand Down Expand Up @@ -439,7 +439,7 @@
:fn route-handler/redirect-to-whiteboard-dashboard!}

:go/keyboard-shortcuts {:binding "g s"
:fn #(route-handler/redirect! {:to :shortcut-setting})}
:fn #(state/pub-event! [:modal/keymap-manager])}

:go/tomorrow {:binding "g t"
:fn journal-handler/go-to-tomorrow!}
Expand Down Expand Up @@ -927,7 +927,10 @@
:dev/show-block-ast
:dev/show-page-data
:dev/show-page-ast
:ui/clear-all-notifications]})
:ui/clear-all-notifications]

:shortcut.category/plugins
[]})

(let [category-maps {::category (set (keys category*))
::dicts/category dicts/categories}]
Expand All @@ -942,10 +945,14 @@
(fn [v]
(vec (remove #(:inactive (get all-default-keyboard-shortcuts %)) v)))))

(def *shortcut-cmds (atom {}))

(defn add-shortcut!
[handler-id id shortcut-map]
(swap! config assoc-in [handler-id id] shortcut-map))
(swap! config assoc-in [handler-id id] shortcut-map)
(swap! *shortcut-cmds assoc id (:cmd shortcut-map)))

(defn remove-shortcut!
[handler-id id]
(swap! config medley/dissoc-in [handler-id id]))
(swap! config medley/dissoc-in [handler-id id])
(swap! *shortcut-cmds dissoc id))