fix(webui): show platform-specific new chat shortcut

This commit is contained in:
Xubin Ren
2026-06-04 14:01:21 +08:00
parent 54d8d3010b
commit 87bd56468c
2 changed files with 49 additions and 2 deletions
+22 -1
View File
@@ -55,12 +55,29 @@ interface SidebarProps {
hostChromeInset?: boolean;
}
type NavigatorWithUserAgentData = Navigator & {
userAgentData?: { platform?: string };
};
function isApplePlatform(): boolean {
if (typeof navigator === "undefined") return false;
const platform = navigator.platform || "";
const userAgentPlatform =
(navigator as NavigatorWithUserAgentData).userAgentData?.platform || "";
return /mac|iphone|ipad|ipod/i.test(`${platform} ${userAgentPlatform}`);
}
function newChatShortcutLabel(): string {
return isApplePlatform() ? "⌘⇧O" : "Ctrl+Shift+O";
}
export function Sidebar(props: SidebarProps) {
const { t } = useTranslation();
const [menuPortalContainer, setMenuPortalContainer] =
useState<HTMLElement | null>(null);
const collapsed = Boolean(props.collapsed);
const toggleLabel = t("thread.header.toggleSidebar");
const newChatShortcut = newChatShortcutLabel();
return (
<nav
@@ -124,7 +141,8 @@ export function Sidebar(props: SidebarProps) {
label={t("sidebar.newChat")}
onClick={props.onNewChat}
icon={<SquarePen className="h-4 w-4" />}
shortcut="Cmd/Ctrl+Shift+O"
shortcut={newChatShortcut}
ariaKeyShortcuts="Meta+Shift+O Control+Shift+O"
/>
<SidebarActionButton
collapsed={collapsed}
@@ -215,6 +233,7 @@ function SidebarActionButton({
active = false,
className,
shortcut,
ariaKeyShortcuts,
}: {
collapsed: boolean;
label: string;
@@ -223,6 +242,7 @@ function SidebarActionButton({
active?: boolean;
className?: string;
shortcut?: string;
ariaKeyShortcuts?: string;
}) {
const title = shortcut ? `${label} (${shortcut})` : collapsed ? label : undefined;
@@ -232,6 +252,7 @@ function SidebarActionButton({
variant="ghost"
aria-label={label}
aria-current={active ? "page" : undefined}
aria-keyshortcuts={ariaKeyShortcuts}
title={title}
onClick={() => onClick()}
className={cn(