mirror of
https://github.com/logseq/logseq.git
synced 2026-05-24 20:54:09 +00:00
Deduplicate binding resolution in ui.cljs and polish keymap UX
Replace hand-rolled binding resolution in dropdown-shortcut and keyboard-shortcut-from-config with calls to dh/shortcut-binding, removing direct dependency on shortcut-config/all-built-in-keyboard-shortcuts and state/custom-shortcuts. Remove unused shortcut-config require. Return focus to trigger button when filter popover closes, matching the pattern already used by the customize popover. Add min-width to active keystroke filter button to prevent width jitter when toggling between label and key-badge states. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -263,22 +263,24 @@
|
||||
;; keystroke filter button
|
||||
(let [filter-popup-id :shortcut-keystroke-filter
|
||||
open-filter! (fn [^js e]
|
||||
(set-q! "")
|
||||
(shui/popup-show!
|
||||
(.-currentTarget e)
|
||||
(fn [_]
|
||||
(keyboard-filter-record-inner
|
||||
keystroke set-keystroke!
|
||||
#(shui/popup-hide! filter-popup-id)))
|
||||
{:id filter-popup-id
|
||||
:force-popover? true
|
||||
:align "end"
|
||||
:content-props
|
||||
{:class "shortcut-filter-popover-content p-0 w-auto"
|
||||
:collision-padding 12
|
||||
:onOpenAutoFocus #(.preventDefault %)
|
||||
:onEscapeKeyDown (fn [_] false)
|
||||
:onPointerDownOutside (fn [_] nil)}}))]
|
||||
(let [anchor-el (.-currentTarget e)]
|
||||
(set-q! "")
|
||||
(shui/popup-show!
|
||||
anchor-el
|
||||
(fn [_]
|
||||
(keyboard-filter-record-inner
|
||||
keystroke set-keystroke!
|
||||
#(shui/popup-hide! filter-popup-id)))
|
||||
{:id filter-popup-id
|
||||
:force-popover? true
|
||||
:align "end"
|
||||
:on-after-hide #(when anchor-el (.focus anchor-el))
|
||||
:content-props
|
||||
{:class "shortcut-filter-popover-content p-0 w-auto"
|
||||
:collision-padding 12
|
||||
:onOpenAutoFocus #(.preventDefault %)
|
||||
:onEscapeKeyDown (fn [_] false)
|
||||
:onPointerDownOutside (fn [_] nil)}})))]
|
||||
(if in-keystroke?
|
||||
[:button.shortcut-keystroke-active
|
||||
{:on-click open-filter!}
|
||||
|
||||
@@ -129,7 +129,7 @@ button.shortcut-feedback-action {
|
||||
select-none;
|
||||
height: 30px;
|
||||
padding: 0 10px;
|
||||
min-width: 0;
|
||||
min-width: 9rem;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--lx-gray-07, var(--ls-quaternary-background-color, var(--rx-gray-07)));
|
||||
background-color: var(--lx-gray-02, var(--ls-secondary-background-color, var(--rx-gray-02)));
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
[frontend.handler.plugin :as plugin-handler]
|
||||
[frontend.mixins :as mixins]
|
||||
[frontend.mobile.util :as mobile-util]
|
||||
[frontend.modules.shortcut.config :as shortcut-config]
|
||||
[frontend.modules.shortcut.core :as shortcut]
|
||||
[frontend.modules.shortcut.data-helper :as shortcut-dh]
|
||||
[frontend.modules.shortcut.utils :as shortcut-utils]
|
||||
@@ -582,12 +581,11 @@
|
||||
:aria-hidden "true"}]]]))
|
||||
|
||||
(defn keyboard-shortcut-from-config [shortcut-name & {:keys [pick-first?]}]
|
||||
(let [built-in-binding (:binding (get shortcut-config/all-built-in-keyboard-shortcuts shortcut-name))
|
||||
custom-binding (when (state/custom-shortcuts) (get (state/custom-shortcuts) shortcut-name))
|
||||
binding (or custom-binding built-in-binding)]
|
||||
(if (and pick-first? (coll? binding))
|
||||
(first binding)
|
||||
(shortcut-utils/decorate-binding binding))))
|
||||
(let [binding (shortcut-dh/shortcut-binding shortcut-name)]
|
||||
(cond
|
||||
(or (nil? binding) (false? binding)) nil
|
||||
(and pick-first? (coll? binding)) (first binding)
|
||||
:else (shortcut-utils/decorate-binding binding))))
|
||||
|
||||
(defn dropdown-shortcut
|
||||
"Renders a compact shui shortcut for use inside dropdown menu items.
|
||||
@@ -595,11 +593,9 @@
|
||||
string (e.g. \"shift+click\"). Returns nil for disabled/missing bindings."
|
||||
[shortcut-or-id]
|
||||
(let [binding (if (keyword? shortcut-or-id)
|
||||
(let [built-in (:binding (get shortcut-config/all-built-in-keyboard-shortcuts shortcut-or-id))
|
||||
custom (when (state/custom-shortcuts) (get (state/custom-shortcuts) shortcut-or-id))
|
||||
b (or custom built-in)]
|
||||
(let [b (shortcut-dh/shortcut-binding shortcut-or-id)]
|
||||
(when (and b (not (false? b)))
|
||||
(if (coll? b) (first b) b)))
|
||||
(first b)))
|
||||
shortcut-or-id)]
|
||||
(when binding
|
||||
[:span.ml-auto.pl-2
|
||||
|
||||
Reference in New Issue
Block a user