-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add main sidebar toggle #3497
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
Add main sidebar toggle #3497
Changes from all commits
699be75
8399d1b
7889515
6cd4760
86f1fb3
c0f9412
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,64 @@ | ||
| import { useEffect, type ReactNode } from "react"; | ||
| import { useAtomValue } from "@effect/atom-react"; | ||
| import { useEffect, type CSSProperties, type ReactNode } from "react"; | ||
| import { useNavigate } from "@tanstack/react-router"; | ||
|
|
||
| import { isElectron } from "../env"; | ||
| import { resolveShortcutCommand, shortcutLabelForCommand } from "../keybindings"; | ||
| import { isMacPlatform } from "../lib/utils"; | ||
| import { primaryServerKeybindingsAtom } from "../state/server"; | ||
| import ThreadSidebar from "./Sidebar"; | ||
| import { Sidebar, SidebarProvider, SidebarRail } from "./ui/sidebar"; | ||
| import { Sidebar, SidebarProvider, SidebarRail, SidebarTrigger, useSidebar } from "./ui/sidebar"; | ||
| import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; | ||
|
|
||
| const THREAD_SIDEBAR_WIDTH_STORAGE_KEY = "chat_thread_sidebar_width"; | ||
| const THREAD_SIDEBAR_MIN_WIDTH = 13 * 16; | ||
| const THREAD_MAIN_CONTENT_MIN_WIDTH = 40 * 16; | ||
| const MACOS_TRAFFIC_LIGHTS_LEFT_INSET = "90px"; | ||
|
|
||
| function SidebarControl() { | ||
| const keybindings = useAtomValue(primaryServerKeybindingsAtom); | ||
| const { toggleSidebar } = useSidebar(); | ||
| const shortcutLabel = shortcutLabelForCommand(keybindings, "sidebar.toggle"); | ||
|
|
||
| useEffect(() => { | ||
| const onKeyDown = (event: KeyboardEvent) => { | ||
| if (event.defaultPrevented) return; | ||
| if (resolveShortcutCommand(event, keybindings) !== "sidebar.toggle") return; | ||
|
|
||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| toggleSidebar(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mod+B blocked after preventDefaultMedium Severity
Reviewed by Cursor Bugbot for commit 41d4e81. Configure here. |
||
| }; | ||
|
|
||
| window.addEventListener("keydown", onKeyDown); | ||
| return () => window.removeEventListener("keydown", onKeyDown); | ||
| }, [keybindings, toggleSidebar]); | ||
|
|
||
| return ( | ||
| <div | ||
| className="pointer-events-none fixed left-[var(--workspace-controls-left)] top-[var(--workspace-controls-top)] z-50 flex h-[var(--workspace-topbar-height)] items-center" | ||
| data-sidebar-control="" | ||
| > | ||
| <Tooltip> | ||
| <TooltipTrigger | ||
| render={ | ||
| <SidebarTrigger className="pointer-events-auto" aria-label="Toggle main sidebar" /> | ||
| } | ||
| /> | ||
| <TooltipPopup side="bottom"> | ||
| Toggle main sidebar{shortcutLabel ? ` (${shortcutLabel})` : ""} | ||
| </TooltipPopup> | ||
| </Tooltip> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export function AppSidebarLayout({ children }: { children: ReactNode }) { | ||
| const navigate = useNavigate(); | ||
| const macosWindowControlsStyle = | ||
| isElectron && isMacPlatform(navigator.platform) | ||
| ? ({ "--workspace-controls-left": MACOS_TRAFFIC_LIGHTS_LEFT_INSET } as CSSProperties) | ||
| : undefined; | ||
|
|
||
| useEffect(() => { | ||
| const onMenuAction = window.desktopBridge?.onMenuAction; | ||
|
|
@@ -28,7 +78,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { | |
| }, [navigate]); | ||
|
|
||
| return ( | ||
| <SidebarProvider className="h-dvh! min-h-0!" defaultOpen> | ||
| <SidebarProvider className="h-dvh! min-h-0!" defaultOpen style={macosWindowControlsStyle}> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WCO inset overridden on MacMedium Severity On macOS Electron, Reviewed by Cursor Bugbot for commit 57cb362. Configure here. |
||
| <Sidebar | ||
| side="left" | ||
| collapsible="offcanvas" | ||
|
|
@@ -44,6 +94,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { | |
| <SidebarRail /> | ||
| </Sidebar> | ||
| {children} | ||
| <SidebarControl /> | ||
| </SidebarProvider> | ||
| ); | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key repeat toggles sidebar repeatedly
Medium Severity
The
sidebar.togglekeydownhandler inSidebarControldoesn't checkevent.repeat, causing the sidebar to toggle rapidly when the shortcut is held down.Reviewed by Cursor Bugbot for commit 57cb362. Configure here.