fix(web): handle sidebar shortcut before editors (#3921)
This commit is contained in:
1 parent
78485e6d50
commit
dfbda84362
2 files changed
+11
-2
No files matched your search
@@ -33,6 +33,12 @@ function SidebarControl() {
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.defaultPrevented) return;
|
||||
if (
|
||||
event.target instanceof HTMLElement &&
|
||||
event.target.closest("[data-keybinding-capture]")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (resolveShortcutCommand(event, keybindings) !== "sidebar.toggle") return;
|
||||
|
||||
event.preventDefault();
|
||||
@@ -40,8 +46,9 @@ function SidebarControl() {
|
||||
toggleSidebar();
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
// Capture before focused editors consume commands such as Mod+B for rich-text formatting.
|
||||
window.addEventListener("keydown", onKeyDown, true);
|
||||
return () => window.removeEventListener("keydown", onKeyDown, true);
|
||||
}, [keybindings, toggleSidebar]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -846,6 +846,7 @@ function KeybindingTableRow({
|
||||
</button>
|
||||
) : (
|
||||
<Input
|
||||
data-keybinding-capture=""
|
||||
autoFocus={isRecording}
|
||||
aria-label={`Keybinding for ${commandLabel(row.command)}`}
|
||||
value={isRecording ? "" : keyDraft}
|
||||
@@ -1011,6 +1012,7 @@ function NewKeybindingTableRow({
|
||||
</div>
|
||||
<div className="flex min-w-0 items-center gap-2 pr-4">
|
||||
<Input
|
||||
data-keybinding-capture=""
|
||||
aria-label={`Keybinding for ${commandLabelText}`}
|
||||
value={isRecording ? "" : keyDraft}
|
||||
placeholder={isRecording ? "Press shortcut" : "Unassigned"}
|
||||
|
||||
Reference in new issue
Block a user