Merge pull request #40660 from NousResearch/bb/keybinds

feat(desktop): rebindable keyboard shortcuts panel
This commit is contained in:
brooklyn!
2026-06-06 12:00:08 -05:00
committed by GitHub
19 changed files with 1228 additions and 119 deletions
+2 -14
View File
@@ -20,7 +20,6 @@ const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
const SIDEBAR_WIDTH = '16rem'
const SIDEBAR_WIDTH_MOBILE = '18rem'
const SIDEBAR_WIDTH_ICON = '3rem'
const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
type SidebarContextProps = {
state: 'expanded' | 'collapsed'
@@ -87,19 +86,8 @@ function SidebarProvider({
return isMobile ? setOpenMobile(open => !open) : setOpen(open => !open)
}, [isMobile, setOpen, setOpenMobile])
// Adds a keyboard shortcut to toggle the sidebar.
React.useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
event.preventDefault()
toggleSidebar()
}
}
window.addEventListener('keydown', handleKeyDown)
return () => window.removeEventListener('keydown', handleKeyDown)
}, [toggleSidebar])
// The sidebar toggle (Cmd/Ctrl+B by default) is owned by the keybind runtime
// (`view.toggleSidebar`) so it appears in the hotkey map and is rebindable.
// We add a state so that we can do data-state="expanded" or "collapsed".
// This makes it easier to style the sidebar with Tailwind classes.