A local-first multi-agent app development platform, built on PenguinHarness
feat(web): six more shortcuts — search, new chat, sidebar, docks, new terminal (#790)
Yaowei Zheng21eabd23880c
diff --git a/changelog/unreleased/2026-09-18-shortcut-commands.md b/changelog/unreleased/2026-09-18-shortcut-commands.mdnew file mode 100644index 00000000..28993b24--- /dev/null+++ b/changelog/unreleased/2026-09-18-shortcut-commands.md@@ -0,0 +1,38 @@+# Six more keyboard shortcuts: search, new chat, sidebar, panels, new terminal++- **Date:** 2026-09-18+- **Type:** feature+- **Scope:** `web`+- **PR:** [#790](https://github.com/Prism-Shadow/penguin-harness/pull/790)++[中文版](2026-09-18-shortcut-commands.zh.md)++Six commands joined the shortcut registry, each rebindable on the Shortcuts settings page (`Mod` is+⌘ on macOS and Ctrl elsewhere): search sessions (Mod+Alt+S), new chat (Mod+Alt+N), show or hide the+sidebar (Mod+Alt+1), the right sidebar (Mod+Alt+2) and the bottom panel (Mod+Alt+3), and new+terminal (`` Ctrl+Shift+` `` on every platform, beside the terminal toggle's `` Ctrl+` ``). The+defaults stay off the browser's own shortcuts — Mod+K searches the web, Mod+N opens a window, Mod+B,+Mod+J and Mod+Shift+O open bookmarks and downloads — except on a Mac, where Chrome also binds ⌥⌘N+(split view), which new chat takes over. The buttons that run the same actions — the panel toggles+in the chat toolbar, the sidebar's search and new-chat buttons, the sidebar collapse and expand+controls — name the chord in their tooltips.++## Details++- Inside a focused terminal the shell keeps every key xterm would send it, bound or not: Ctrl+B+ stays tmux's prefix, and on Linux the Ctrl+Alt chords reach the shell as Meta. The app commands+ still reachable from a terminal are the chords xterm sends nothing for — `` Ctrl+` ``,+ `` Ctrl+Shift+` ``, every ⌘ chord on a Mac, and on Windows the Ctrl+Alt chords, which xterm+ leaves to AltGr.+- A key typed with AltGr (Windows reports it as Ctrl+Alt) is typing, not a chord: `ś` stays typable+ on the Polish layout although its keys read as Mod+Alt+S.+- Search sessions opens the sidebar's search field, or puts the caret back into an open one; on the+ collapsed rail one press expands the sidebar with the field open and focused. New chat does what+ every other New chat does, parking typed-but-unsent text first, and works with the sidebar+ collapsed. Both are development-mode commands: in company mode they leave the key to the browser.+- A command whose target is not on screen leaves the key to the browser too: the sidebar commands+ below the `md` breakpoint (where the pinned sidebar is not shown), and the panel and terminal+ commands on pages without docks — organization pages, the login page, the standalone terminal+ page — so a new terminal is never spawned into a hidden dock. Global commands also stay quiet+ while a dialog or menu is open.+- The settings page's Panels group, empty until now, holds the sidebar and panel toggles.diff --git a/changelog/unreleased/2026-09-18-shortcut-commands.zh.md b/changelog/unreleased/2026-09-18-shortcut-commands.zh.mdnew file mode 100644index 00000000..c8d95b7b--- /dev/null+++ b/changelog/unreleased/2026-09-18-shortcut-commands.zh.md@@ -0,0 +1,18 @@+# 新增六条快捷键:搜索、新建对话、侧栏、面板、新建终端++- **Date:** 2026-09-18+- **Type:** feature+- **Scope:** `web`+- **PR:** [#790](https://github.com/Prism-Shadow/penguin-harness/pull/790)++[English](2026-09-18-shortcut-commands.md)++快捷键注册表新增六条命令,都可在设置的「快捷键」页改绑(`Mod` 在 macOS 为 ⌘,其余平台为 Ctrl):搜索会话(Mod+Alt+S)、新建对话(Mod+Alt+N)、显示或隐藏侧栏(Mod+Alt+1)、右侧栏(Mod+Alt+2)与下侧栏(Mod+Alt+3),以及新建终端(所有平台均为 `` Ctrl+Shift+` ``,与显示 / 隐藏终端的 `` Ctrl+` `` 相邻)。缺省组合避开浏览器自身的快捷键——Mod+K 是网页搜索,Mod+N 打开新窗口,Mod+B、Mod+J 与 Mod+Shift+O 打开书签与下载——只有 Mac 上 Chrome 还把 ⌥⌘N 用作分屏,新建对话会接管它。执行同一动作的按钮——对话工具行的面板开关、侧栏的搜索与新建对话按钮、侧栏的折叠与展开控件——在悬停提示里写明组合。++## 细节++- 终端有焦点时,xterm 会送给 shell 的按键仍归 shell,无论是否绑定:Ctrl+B 仍是 tmux 前缀,Linux 上的 Ctrl+Alt 组合以 Meta 送给 shell。终端里仍能触发的应用命令只有 xterm 自身不发送的组合——`` Ctrl+` ``、`` Ctrl+Shift+` ``、Mac 上的全部 ⌘ 组合,以及 Windows 上的 Ctrl+Alt 组合(xterm 把它们留给 AltGr)。+- 用 AltGr 输入的字符(Windows 把它报成 Ctrl+Alt)视为输入而非组合:波兰语键盘布局上的 `ś` 虽然按键读作 Mod+Alt+S,仍可照常输入。+- 搜索会话打开侧栏的搜索框,已打开时把光标放回其中;在收起的图标栏上按一次即展开侧栏并打开、聚焦搜索框。新建对话与其他各处的新建对话一致,先把已输入未发送的文字停放为草稿,侧栏收起时同样可用。两者都是开发模式的命令:公司模式下把按键留给浏览器。+- 目标不在屏幕上的命令同样把按键留给浏览器:`md` 断点以下(固定侧栏不显示)的侧栏命令,以及没有停靠栏的页面——组织页、登录页、独立终端页——上的面板与终端命令,因而不会向隐藏的停靠栏里新建终端。对话框或菜单打开期间,全局命令也不触发。+- 设置页此前为空的「面板」分组现在放置侧栏与面板的开关。diff --git a/packages/docs/content/chat.en.md b/packages/docs/content/chat.en.mdindex 00390981..1bbef176 100644--- a/packages/docs/content/chat.en.md+++ b/packages/docs/content/chat.en.md@@ -246,7 +246,10 @@ Good to know:Terminals open as tabs in the docks, or on the standalone `/terminal` page.- Ctrl+` shows or hides the terminal tabs. With no terminal open, it takes over a running shell no conversation holds, or starts a new one.-- Ctrl+W, with a terminal focused, closes that terminal after a confirmation, like the × on its tab. The keystroke never reaches the shell. Browsers reserve Ctrl+W for closing the browser tab and may act on it first; the desktop app passes it to the terminal.+- Ctrl+Shift+` starts a new terminal in the docks.+- Ctrl+Alt+`, with a terminal focused, closes that terminal after a confirmation, like the × on its tab. The keystroke never reaches the shell. Ctrl+W does: it is readline's delete-word.++The three terminal keys use the Control key on a Mac too.## Check Session stats@@ -349,8 +352,17 @@ A group's active conversations, and each open folder, show ten conversations at| Shift+F10 | Open the menu of the focused conversation row, or of the Files panel || Esc | Close a menu; fold the shortcuts launcher; cancel a pending threshold change || Left / Right | Move the focused compaction threshold marker by 1,000 Tokens (10,000 with Shift) |+| Ctrl+Alt+S | Open **Search chats** in the sidebar |+| Ctrl+Alt+N | Start a new chat |+| Ctrl+Alt+1 | Show or hide the sidebar |+| Ctrl+Alt+2 | Show or hide the right sidebar |+| Ctrl+Alt+3 | Show or hide the bottom panel || Ctrl+` | Show or hide the terminal tabs |-| Ctrl+W | Close the focused terminal, after confirmation |+| Ctrl+Shift+` | Start a new terminal |+| Ctrl+Alt+` | Close the focused terminal, after confirmation |+| Ctrl+S | Save in the Files panel's editor or the handbook |++On a Mac, ⌘ takes the place of Ctrl in Ctrl+S and in the Ctrl+Alt rows other than the terminal's (⌘S, ⌥⌘S); the three terminal keys use the Control key there too. Every row from Ctrl+Alt+S down is a default: change it under [System settings › Keyboard shortcuts](/settings#keyboard-shortcuts).## Limitsdiff --git a/packages/docs/content/chat.zh.md b/packages/docs/content/chat.zh.mdindex 6560a132..4222214b 100644--- a/packages/docs/content/chat.zh.md+++ b/packages/docs/content/chat.zh.md@@ -246,7 +246,10 @@ Session 的模型是锁定的,点击模型名称会提示「输入 /model 切终端以标签页的形式出现在侧栏里,也可以在独立的 `/terminal` 页面中打开。- Ctrl+` 显示或隐藏终端标签页。没有打开的终端时,会接管一个没有被任何对话占用、仍在运行的 Shell,或者新建一个。-- 终端获得焦点时按 Ctrl+W,确认后关闭这个终端,与点击标签页上的 × 效果相同。这个按键不会传给 Shell。浏览器把 Ctrl+W 留给关闭浏览器标签页,可能会先响应;桌面应用会把它交给终端。+- Ctrl+Shift+` 在侧栏里新建一个终端。+- 终端获得焦点时按 Ctrl+Alt+`,确认后关闭这个终端,与点击标签页上的 × 效果相同。这个按键不会传给 Shell;Ctrl+W 则会传给 Shell,是 readline 的删词。++这三个终端按键在 Mac 上同样用 Control 键。## 查看 Session 统计@@ -349,8 +352,17 @@ Session 的模型是锁定的,点击模型名称会提示「输入 /model 切| Shift+F10 | 打开当前聚焦的对话行或文件浏览面板的右键菜单 || Esc | 关闭菜单;收起快捷方式悬浮球;取消待确认的阈值修改 || 左 / 右方向键 | 聚焦压缩阈值标记时,每次移动 1,000 Token(按住 Shift 为 10,000) |+| Ctrl+Alt+S | 打开侧边栏的**搜索会话** |+| Ctrl+Alt+N | 新建对话 |+| Ctrl+Alt+1 | 显示或隐藏侧边栏 |+| Ctrl+Alt+2 | 显示或隐藏右侧栏 |+| Ctrl+Alt+3 | 显示或隐藏下侧栏 || Ctrl+` | 显示或隐藏终端标签页 |-| Ctrl+W | 确认后关闭当前聚焦的终端 |+| Ctrl+Shift+` | 新建终端 |+| Ctrl+Alt+` | 确认后关闭当前聚焦的终端 |+| Ctrl+S | 在文件浏览面板的编辑器或手册中保存 |++在 Mac 上,Ctrl+S 以及终端之外的 Ctrl+Alt 组合里,Ctrl 换成 ⌘(⌘S、⌥⌘S);三个终端按键在 Mac 上同样用 Control 键。从 Ctrl+Alt+S 起的各行都是缺省组合,可以在[系统设置 › 快捷键](/settings#快捷键)中修改。## 限制diff --git a/packages/docs/content/settings.en.md b/packages/docs/content/settings.en.mdindex 1f3b0817..36918a9c 100644--- a/packages/docs/content/settings.en.md+++ b/packages/docs/content/settings.en.md@@ -5,7 +5,7 @@ description: Manage your profile, preferences and password, and, as an admin, us**Settings** is one dialog for the settings that belong to neither a Project nor an agent: your profile, your interface preferences and password, and, for an admin, the server's users, proxy, upload limits, company mode and plugins, the sandbox among them.-- Your own settings: [Profile](#profile), [General](#general), [Appearance](#appearance) and [Account](#account).+- Your own settings: [Profile](#profile), [General](#general), [Appearance](#appearance), [Keyboard shortcuts](#keyboard-shortcuts) and [Account](#account).- Server settings, for admins: [Users](#users), [Proxy options](#proxy-options), [Upload limits](#upload-limits), [Company mode](#company-mode) and [Plugins](#plugins).## Open Settings@@ -24,6 +24,7 @@ The rail is grouped into **Personal** and **Server**:| [Profile](#profile) | Personal | Everyone || [General](#general) | Personal | Everyone || [Appearance](#appearance) | Personal | Everyone |+| [Keyboard shortcuts](#keyboard-shortcuts) | Personal | Everyone || [Account](#account) | Personal | Only where a password exists to change || [Users](#users) | Server | Admin only, and not in the desktop app || [Proxy options](#proxy-options) | Server | Admin only |@@ -36,7 +37,7 @@ Personal preferences apply the moment they are touched. There is no Save buttonWhere your personal preferences are stored:- In this browser: language, currency, notifications, theme, terminal theme, font size, accent, the shortcuts launcher, and tool short names.-- With your account on the server: your profile and your personal Company mode switch.+- With your account on the server: your profile, your keyboard shortcuts and your personal Company mode switch.The Server pages are admin-only and server-global. A non-admin sees neither those entries nor any hint that they exist: they are left with the Personal pages alone, and the rail draws no group headings at all.@@ -130,6 +131,24 @@ About **Tray icon**: the desktop app keeps an icon in the system tray: the WindoTurning it off removes the icon at once, with no restart. Closing the window then no longer hides it there: the app stays in the Dock on macOS, and quits on Windows and Linux.+## Keyboard shortcuts++The **Keyboard shortcuts** page is personal. It lists every command you can rebind, by group, each with its current key combination as your platform writes it: ⌥⌘S on a Mac, Ctrl+Alt+S elsewhere. The defaults are listed under [Keyboard shortcuts](/chat#keyboard-shortcuts) in Chat.++1. Select the combination on a row. The button waits for a new one.+2. Press the new combination. Esc cancels, and Backspace or Delete clears the binding. A combination needs Ctrl or Alt (⌘ or ⌃ on a Mac) unless it is an F key: Shift alone, and Option alone on a Mac, is typing.++A changed row gets a **Restore default** button, and **Reset all** restores every row at once. A change applies at once in every tab of this browser; your other browsers and the desktop app pick it up the next time they load. Bindings are kept per platform, so a Mac and a Windows machine each have their own.++As soon as a binding is set, the line under its row says what stands in its way:++- Another command on the same combination: which of the two fires.+- A combination the browser keeps for itself, such as Ctrl+W or ⌘W: it only works in the desktop app. This note is amber.+- In the desktop app, a combination its menu also carries: the binding overrides that menu item.+- A combination the browser also uses, such as Ctrl+P or ⌘P for printing: in a browser tab, the binding takes over that browser function.++Bindings are shared by your browsers and the desktop app, so the browser's notes show in the desktop app too. No default sits on a combination the browser keeps. Save keeps Ctrl+S / ⌘S and takes over the browser's Save Page while an editor has focus, so its row carries a note; on a Mac so do the two rows whose defaults Chrome also uses, ⌥⌘P and ⌥⌘N.+## AccountThe **Account** page holds the **Change password** action.diff --git a/packages/docs/content/settings.zh.md b/packages/docs/content/settings.zh.mdindex d36b9167..0fbb03d5 100644--- a/packages/docs/content/settings.zh.md+++ b/packages/docs/content/settings.zh.md@@ -5,7 +5,7 @@ description: 管理个人资料、偏好设置和密码;管理员还可以管**设置**把不属于 Project 也不属于 Agent 的设置集中在一个对话框里:你的个人资料、界面偏好和密码;管理员还能在这里管理服务器的用户、代理、上传限制、公司模式和插件(包括沙盒)。-- 个人设置:[个人资料](#个人资料)、[通用](#通用)、[外观](#外观)和[账户](#账户)。+- 个人设置:[个人资料](#个人资料)、[通用](#通用)、[外观](#外观)、[快捷键](#快捷键)和[账户](#账户)。- 服务器设置,仅管理员:[用户管理](#用户管理)、[代理选项](#代理选项)、[上传限制](#上传限制)、[公司模式](#公司模式)和[插件](#插件)。## 打开设置@@ -24,6 +24,7 @@ description: 管理个人资料、偏好设置和密码;管理员还可以管| [个人资料](#个人资料) | 个人 | 所有人 || [通用](#通用) | 个人 | 所有人 || [外观](#外观) | 个人 | 所有人 |+| [快捷键](#快捷键) | 个人 | 所有人 || [账户](#账户) | 个人 | 仅在有密码可改时出现 || [用户管理](#用户管理) | 服务器 | 仅管理员,桌面应用中没有 || [代理选项](#代理选项) | 服务器 | 仅管理员 |@@ -36,7 +37,7 @@ description: 管理个人资料、偏好设置和密码;管理员还可以管个人偏好的存储位置:- 保存在当前浏览器:语言、币种、任务完成通知、主题、终端主题、字号、主题色、快捷方式悬浮球和工具短名。-- 随账户保存在服务器:个人资料,以及你个人的公司模式开关。+- 随账户保存在服务器:个人资料、快捷键,以及你个人的公司模式开关。服务器组的页面仅管理员可见,作用于整台服务器。非管理员既看不到这些条目,也无从得知它们存在:他们只能看到个人组的几页,导航也不再显示分组标题。@@ -130,6 +131,24 @@ Trace 会成为该 Agent 的一段新对话。如果该 Agent 下已有相同 id关掉后图标立即消失,无需重启。此后关闭窗口不再收进托盘:macOS 上应用留在 Dock 中,Windows 和 Linux 上则直接退出。+## 快捷键++**快捷键**页是个人设置。它按分组列出所有可以改绑的命令,每行按平台写法显示当前的组合:Mac 上为 ⌥⌘S,其余平台为 Ctrl+Alt+S。各命令的缺省组合见「对话」中的[快捷键](/chat#快捷键)。++1. 点击某一行的组合,按钮开始等待新的组合。+2. 按下新的组合。Esc 取消,Backspace 或 Delete 清除绑定。组合必须带 Ctrl 或 Alt(Mac 上为 ⌘ 或 ⌃),F 键除外:单独的 Shift,以及 Mac 上单独的 Option,只是输入。++改过的行会出现**恢复默认**按钮,**全部恢复默认**一次恢复所有行。改动立即生效,当前浏览器的其他标签页同步跟随;你的其他浏览器和桌面应用在下次加载时取得。绑定按平台分别保存,Mac 和 Windows 各有一套。++绑定一设好,这一行下方就会说明挡在它前面的东西:++- 另一条命令使用同一组合:说明两条中哪一条生效。+- 浏览器自己保留的组合,例如 Ctrl+W 或 ⌘W:只在桌面应用里生效。这条提示为琥珀色。+- 在桌面应用中,菜单同样带有的组合:绑定会覆盖那个菜单项。+- 浏览器本身也用的组合,例如打印的 Ctrl+P 或 ⌘P:在浏览器标签页里,绑定会取代浏览器的那个功能。++绑定由你的浏览器和桌面应用共用,所以浏览器相关的提示在桌面应用里也会出现。缺省组合都不落在浏览器保留的组合上。保存仍是 Ctrl+S / ⌘S,编辑器有焦点时取代浏览器的「另存网页」,所以这一行带有提示;在 Mac 上,缺省组合也被 Chrome 使用的两行(⌥⌘P 与 ⌥⌘N)同样带有提示。+## 账户**账户**页提供**修改密码**操作。diff --git a/packages/web/src/components/layout/app-layout.tsx b/packages/web/src/components/layout/app-layout.tsxindex 714af7fe..876067c5 100644--- a/packages/web/src/components/layout/app-layout.tsx+++ b/packages/web/src/components/layout/app-layout.tsx@@ -9,6 +9,8 @@ import { NavLink, Outlet, useLocation, useMatch, useNavigate } from "react-routeimport * as api from "../../api/endpoints";import { nagsAboutInitialPassword } from "../../lib/account-menu";import { S } from "../../lib/strings";+import { onCommand } from "../../lib/shortcuts/dispatcher";+import { useShortcutTitle } from "../../lib/shortcuts/use-keymap";import { latestConversation, withoutOrgSessions } from "../../lib/session-grouping";import { navNoteFor, useUpdateBadges } from "../../lib/use-update-badges";import { useAuth } from "../../state/auth";@@ -35,7 +37,7 @@ import {import { NEW_CHAT_ICON, Sidebar } from "./sidebar";import { UserMenu } from "./user-menu";import { DRAFT_SESSION_ID } from "../../features/chat/chat-page";-import { prepareNewChatDraft } from "../../features/chat/new-chat";+import { useNewChat } from "../../features/chat/use-new-chat";import { ChangePasswordDialog } from "../account/change-password-dialog";import { UpdateModal } from "../account/update-modal";import { TerminalDockRuntime } from "../../features/terminal/terminal-view-pool";@@ -53,6 +55,15 @@ import { toneStrip } from "../../lib/tone";*/const HISTORY_ICON = "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5M12 7v5l4 2";+/**+ * Whether the pinned sidebar (or its rail) is on screen: the `<aside>` below is `hidden md:block`,+ * and Tailwind's `md` is 768px at the browser's default font size — a media query ignores the+ * app's 18px root. Below it the drawer's own sidebar answers the commands while it is open.+ */+function pinnedSidebarOnScreen(): boolean {+ return typeof window !== "undefined" && window.matchMedia("(min-width: 768px)").matches;+}+/** Shared look of rail entries (icon buttons and NavLinks alike): solid gray fill when active, gray hover otherwise. `relative` so an entry can anchor an update badge on its corner (no z-index, so it still creates no stacking context). */const railItemClass = (active: boolean) =>`relative flex h-8 w-8 items-center justify-center rounded-md transition-colors duration-150 ${@@ -112,11 +123,8 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {navigate(`/chat/${lastSession.sessionId}`);};- /** Mirrors the pinned sidebar's "New chat": parks any typed-but-unsent draft text first, then opens a draft that names nothing, so it starts on the Project's new-chat defaults (new-chat.ts). */- const newChat = () => {- if (user && currentProject) prepareNewChatDraft(user.userId, currentProject.projectId);- navigate(`/chat/${DRAFT_SESSION_ID}`);- };+ /** Mirrors the pinned sidebar's "New chat" (use-new-chat.ts): parks any typed-but-unsent draft text first, then opens a draft that names nothing, so it starts on the Project's new-chat defaults. */+ const newChat = useNewChat();/** Page entries (rail positions 3-8): same routes, same labels as the pinned nav.Traces is not among them: reading a Trace happens in the chat toolbar's panel@@ -184,10 +192,11 @@ function CollapsedRail({ onExpand }: { onExpand: () => void }) {badges.softwareNote !== null? `${S.nav.userSettings} · ${badges.softwareNote}`: S.nav.userSettings;+ const expandTitle = useShortcutTitle(S.nav.expandSidebar, "sidebar.toggle");return (<div className="flex h-full flex-col items-center gap-1 py-2.5">- <Tooltip label={S.nav.expandSidebar} className="shrink-0">+ <Tooltip label={expandTitle} className="shrink-0"><buttontype="button"aria-label={S.nav.expandSidebar}@@ -422,6 +431,38 @@ export function AppLayout() {localStorage.setItem("penguin.sidebarCollapsed", next ? "1" : "0");return next;});+ // The commands whose surface is this layout. Each declines (returns false, so the browser's+ // own key runs) when its effect could not be seen: the pinned sidebar exists only from the+ // `md` breakpoint up (below it the drawer's own sidebar answers while open), and company mode+ // has neither a session search nor a development New chat. New chat runs from here rather+ // than from the sidebar so it works with the sidebar collapsed to its rail. The search field+ // only exists in the expanded sidebar: with the rail showing, the command expands the sidebar+ // with the field already open (the pinned Sidebar mounts fresh on every expand and takes the+ // flag as its initial state); otherwise it declines and the sidebar's own handler takes it.+ const inCompany = company.workMode === "company";+ const newChat = useNewChat();+ const [openSearchOnExpand, setOpenSearchOnExpand] = useState(false);+ useEffect(() => {+ const offs = [+ onCommand("sidebar.toggle", () => {+ if (!pinnedSidebarOnScreen()) return false;+ setOpenSearchOnExpand(false);+ toggleCollapsed();+ }),+ onCommand("chat.new", () => {+ if (inCompany) return false;+ newChat();+ }),+ onCommand("sessions.search", () => {+ if (inCompany || !pinnedSidebarOnScreen() || !collapsed) return false;+ setOpenSearchOnExpand(true);+ toggleCollapsed();+ }),+ ];+ return () => {+ for (const off of offs) off();+ };+ }, [collapsed, inCompany, newChat]);return (<div className="flex h-full">@@ -444,9 +485,20 @@ export function AppLayout() {><div className={`h-full ${collapsed ? "w-12" : "w-64 lg:w-72"}`}>{collapsed ? (- <CollapsedRail onExpand={toggleCollapsed} />+ <CollapsedRail+ onExpand={() => {+ setOpenSearchOnExpand(false);+ toggleCollapsed();+ }}+ />) : (- <Sidebar onCollapse={toggleCollapsed} />+ <Sidebar+ onCollapse={() => {+ setOpenSearchOnExpand(false);+ toggleCollapsed();+ }}+ initialSearchOpen={openSearchOnExpand}+ />)}</div></aside>diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsxindex 9d6586bb..cb28a4bc 100644--- a/packages/web/src/components/layout/sidebar.tsx+++ b/packages/web/src/components/layout/sidebar.tsx@@ -47,6 +47,8 @@ import type {import * as api from "../../api/endpoints";import { S } from "../../lib/strings";import { formatRelativeShort } from "../../lib/format";+import { onCommand } from "../../lib/shortcuts/dispatcher";+import { useShortcutTitle } from "../../lib/shortcuts/use-keymap";import { sessionBackgroundTasks, sessionRowActivity } from "../../lib/session-activity";import type { SessionActivity } from "../../lib/session-activity";import { forgetSession, noteSessionSeen, useSessionSeen } from "../../lib/session-seen";@@ -379,9 +381,12 @@ function StatusGlyph({ activity }: { activity: SessionActivity }) {export function Sidebar({onNavigate,onCollapse,+ initialSearchOpen = false,}: {onNavigate?: () => void;onCollapse?: () => void;+ /** Mount with the session search open and focused: the search shortcut pressed on the collapsed rail. */+ initialSearchOpen?: boolean;}) {const navigate = useNavigate();const location = useLocation();@@ -528,7 +533,26 @@ export function Sidebar({label: string;} | null>(null);/** Live title search: the input's visibility and its query (transient — never persisted). */- const [searchOpen, setSearchOpen] = useState(false);+ const [searchOpen, setSearchOpen] = useState(initialSearchOpen);+ const searchInputRef = useRef<HTMLInputElement | null>(null);+ const rootRef = useRef<HTMLDivElement | null>(null);+ const searchTitle = useShortcutTitle(S.chat.searchSessions, "sessions.search");+ const newChatTitle = useShortcutTitle(S.chat.newSessionMenu, "chat.new");+ const collapseTitle = useShortcutTitle(S.nav.collapseSidebar, "sidebar.toggle");+ // The sessions.search command: open the field, or put the caret back into an open one. It+ // declines (the browser's own key runs) when the field could not be seen: company mode has+ // no session list, and the pinned sidebar is `display: none` below the `md` breakpoint while+ // still mounted. Re-registered when the field opens or closes so the handler reads the state.+ useEffect(+ () =>+ onCommand("sessions.search", () => {+ if (inCompany) return false;+ if (rootRef.current !== null && rootRef.current.getClientRects().length === 0) return false;+ if (searchOpen) searchInputRef.current?.focus();+ else setSearchOpen(true);+ }),+ [searchOpen, inCompany],+ );const [searchQuery, setSearchQuery] = useState("");/** Header list-settings dropdown (grouping + sort radios). */const [listSettingsOpen, setListSettingsOpen] = useState(false);@@ -1772,7 +1796,7 @@ export function Sidebar({}));return (- <div className="flex h-full w-full flex-col">+ <div ref={rootRef} className="flex h-full w-full flex-col">{/* The work-mode switch, above the Project switcher: 开发 | 公司. Rendered only whilecompany mode is available (the admin master switch and the user's own switch bothon); the choice persists per user. The 内测版 tag rides on 公司 — the switch is the@@ -1800,7 +1824,7 @@ export function Sidebar({{onCollapse && (<buttontype="button"- title={S.nav.collapseSidebar}+ title={collapseTitle}aria-label={S.nav.collapseSidebar}onClick={onCollapse}className="flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-gray-400 transition-colors duration-150 hover:bg-gray-200/70 hover:text-gray-800 dark:text-gray-500 dark:hover:bg-gray-800 dark:hover:text-gray-200"@@ -1893,6 +1917,7 @@ export function Sidebar({<div className="shrink-0 px-2 pb-2 pt-2"><buttontype="button"+ title={newChatTitle}onClick={() => newChat()}className={`flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-sm font-medium transition-colors duration-150 ${activeSessionId === DRAFT_SESSION_ID@@ -2081,6 +2106,7 @@ export function Sidebar({<Icon d={SEARCH_ICON} size={12} /></span><input+ ref={searchInputRef}autoFocusvalue={searchQuery}placeholder={S.chat.searchSessionsPlaceholder}@@ -2108,7 +2134,7 @@ export function Sidebar({) : (<buttontype="button"- title={S.chat.searchSessions}+ title={searchTitle}aria-label={S.chat.searchSessions}onClick={() => setSearchOpen(true)}className={headerControlClass(false)}diff --git a/packages/web/src/components/ui/modal.tsx b/packages/web/src/components/ui/modal.tsxindex 0a513ae1..52806a0a 100644--- a/packages/web/src/components/ui/modal.tsx+++ b/packages/web/src/components/ui/modal.tsx@@ -19,6 +19,7 @@import { useEffect, useId, useRef } from "react";import { createPortal } from "react-dom";import type { KeyboardEvent as ReactKeyboardEvent, ReactNode, RefObject } from "react";+import { setShortcutBlocker } from "../../lib/shortcuts/dispatcher";import { CloseButton } from "./icons";export interface ModalProps {@@ -73,6 +74,13 @@ export function isTopEscLayer(id: symbol): boolean {return escLayers[escLayers.length - 1] === id;}+/** Whether any dialog or menu is open — the state in which a global shortcut must not run behind it. */+export function hasEscLayers(): boolean {+ return escLayers.length > 0;+}++setShortcutBlocker(hasEscLayers);+/*** The elements an overlay hands focus to, in DOM order. Shared with Dropdown so a dialog and* a menu agree on what "focusable" means. Visually hidden controls stay in the set ondiff --git a/packages/web/src/features/chat/panels-toolbar.tsx b/packages/web/src/features/chat/panels-toolbar.tsxindex 4eb88bb2..a4df565c 100644--- a/packages/web/src/features/chat/panels-toolbar.tsx+++ b/packages/web/src/features/chat/panels-toolbar.tsx@@ -14,6 +14,7 @@ import { S } from "../../lib/strings";import { GlyphIcon } from "../../components/ui/glyph-icon";import { PANEL_BOTTOM_ICON, PANEL_RIGHT_ICON } from "../../components/ui/icons";import { ICON_SIZE } from "../../lib/icon-scale";+import { useShortcutTitle } from "../../lib/shortcuts/use-keymap";import { toneDot } from "../../lib/tone";import {dockVersion,@@ -42,14 +43,16 @@ export function PanelsToolbar({ agentsPending }: PanelsToolbarProps) {// button — the edge the panel opens on.const pendingDock: DockPosition = panelDock("agents") ?? "right";- const toggles: Array<{ position: DockPosition; label: string; icon: string }> = [- { position: "bottom", label: S.dock.bottomDock, icon: PANEL_BOTTOM_ICON },- { position: "right", label: S.dock.rightDock, icon: PANEL_RIGHT_ICON },+ const bottomTitle = useShortcutTitle(S.dock.bottomDock, "dock.toggleBottom");+ const rightTitle = useShortcutTitle(S.dock.rightDock, "dock.toggleRight");+ const toggles: Array<{ position: DockPosition; label: string; title: string; icon: string }> = [+ { position: "bottom", label: S.dock.bottomDock, title: bottomTitle, icon: PANEL_BOTTOM_ICON },+ { position: "right", label: S.dock.rightDock, title: rightTitle, icon: PANEL_RIGHT_ICON },];return (<div className="flex shrink-0 items-center gap-1" data-testid="panels-toolbar">- {toggles.map(({ position, label, icon }) => (+ {toggles.map(({ position, label, title, icon }) => (<buttonkey={position}type="button"@@ -57,7 +60,7 @@ export function PanelsToolbar({ agentsPending }: PanelsToolbarProps) {// Hiding a dock keeps every body mounted (dock-panel.tsx renders it at zero// size), so a tab holding unsaved work has nothing to lose and nothing to ask.onClick={() => toggleDock(position)}- title={label}+ title={title}aria-label={label}data-testid={`dock-toggle-${position}`}className={triggerClass(isDockVisible(position))}diff --git a/packages/web/src/features/chat/use-new-chat.ts b/packages/web/src/features/chat/use-new-chat.tsnew file mode 100644index 00000000..861fcb13--- /dev/null+++ b/packages/web/src/features/chat/use-new-chat.ts@@ -0,0 +1,25 @@+/**+ * The generic "New chat" as one hook, so every entry point that names nothing — the collapsed+ * rail's entry, the `chat.new` shortcut — does what the sidebar's pinned button does: park any+ * typed-but-unsent draft text and release a text-less draft's leftover selections+ * (prepareNewChatDraft, which says why every entry point must), then open the draft page, which+ * starts on the Project's new-chat defaults.+ */+import { useCallback } from "react";+import { useNavigate } from "react-router";+import { useAuth } from "../../state/auth";+import { useProject } from "../../state/project";+import { DRAFT_SESSION_ID } from "./chat-page";+import { prepareNewChatDraft } from "./new-chat";++export function useNewChat(): () => void {+ const { user } = useAuth();+ const { currentProject } = useProject();+ const navigate = useNavigate();+ const userId = user?.userId ?? null;+ const projectId = currentProject?.projectId ?? null;+ return useCallback(() => {+ if (userId !== null && projectId !== null) prepareNewChatDraft(userId, projectId);+ navigate(`/chat/${DRAFT_SESSION_ID}`);+ }, [userId, projectId, navigate]);+}diff --git a/packages/web/src/features/dock/dock-state.ts b/packages/web/src/features/dock/dock-state.tsindex bb3c4c27..eb2b1dfc 100644--- a/packages/web/src/features/dock/dock-state.ts+++ b/packages/web/src/features/dock/dock-state.ts@@ -329,6 +329,15 @@ export function currentDockScope(): string {return scope;}+/**+ * Whether a page with docks is on screen. Pages without them (organization pages, login, the+ * standalone /terminal page) sit on the `~none` placeholder, where a dock command would act on+ * nothing visible — or worse, spawn shells into an arrangement the next conversation inherits.+ */+export function docksOnScreen(): boolean {+ return scope !== NO_SCOPE;+}+// ------------------------------------------------------------------------------- narrow/**diff --git a/packages/web/src/features/dock/dock-terminal.ts b/packages/web/src/features/dock/dock-terminal.tsindex 49def4ef..3333e558 100644--- a/packages/web/src/features/dock/dock-terminal.ts+++ b/packages/web/src/features/dock/dock-terminal.ts@@ -17,9 +17,11 @@ import { machineForTerminal, rememberTerminalMachine } from "../../lib/terminal-import {addTerminalTab,currentDockScope,+ docksOnScreen,removeTab,restoreTerminalTab,showTerminal,+ toggleDock,toggleTerminalDocks,unownedTerminals,type DockPosition,@@ -189,3 +191,20 @@ export { showTerminal };onCommand("terminal.toggle", () => {toggleTerminal();});+// The other dock commands live here for the same reason: the store (dock-state.ts) stays+// free of the dispatcher, and this module is evaluated wherever the docks can appear. Each+// declines on a page without docks (the browser's own key then runs): a toggle there would+// flip nothing visible, and a new terminal would spawn a server shell into the placeholder+// arrangement the next conversation inherits.+onCommand("terminal.new", () => {+ if (!docksOnScreen()) return false;+ void createShellInDock();+});+onCommand("dock.toggleRight", () => {+ if (!docksOnScreen()) return false;+ toggleDock("right");+});+onCommand("dock.toggleBottom", () => {+ if (!docksOnScreen()) return false;+ toggleDock("bottom");+});diff --git a/packages/web/src/features/terminal/terminal-view.tsx b/packages/web/src/features/terminal/terminal-view.tsxindex 4d0bcfeb..858bd7e5 100644--- a/packages/web/src/features/terminal/terminal-view.tsx+++ b/packages/web/src/features/terminal/terminal-view.tsx@@ -18,7 +18,6 @@ import type { ITheme, Terminal as XTerminal } from "@xterm/xterm";import { TerminalOpcode, decodeFrame, encodeFrame, encodeResize } from "./terminal-frames";import { LinkClickTracker, openTerminalLink, positionFromPointer } from "./terminal-links";import { useTheme } from "../../state/theme";-import { hasCommandHandler } from "../../lib/shortcuts/dispatcher";import { currentPlatform } from "../../lib/shortcuts/platform";import { keymap } from "../../lib/shortcuts/store";import { terminalClipboardAction } from "../../lib/shortcuts/terminal-clipboard";@@ -392,13 +391,14 @@ export function TerminalView({* into xterm's textarea (no clipboard permission involved), so returning false —* skip xterm's own key handling, keep the browser default — is the whole* implementation, and calling the async clipboard API as well would double-paste.- * 2. The keymap (lib/shortcuts/terminal-keys.ts decides). A terminal-scope command+ * 2. The keymap (lib/shortcuts/terminal-keys.ts decides). The terminal-scope command* (`terminal.close`, ⌃⌥` / Ctrl+Alt+` by default) is consumed here so it never- * reaches the shell. A global-scope command with a handler (Ctrl+` toggling the docks)- * is not sent to the shell either, but is left un-prevented so it bubbles to the- * window dispatcher that owns it — VS Code's "commands to skip shell". Anything else,- * including a chord no surface answers and Ctrl+W (readline's delete-word), goes to- * the shell as typed.+ * reaches the shell. Everything else is xterm's: the shell keeps every key xterm would+ * send it, even one an app command is bound to (Ctrl+W, tmux's Ctrl+B, and on Linux+ * the Ctrl+Alt chords, which xterm sends as Meta), and the chords xterm sends nothing+ * for — Ctrl+`, Ctrl+Shift+`, every ⌘ chord, and on Windows the Ctrl+Alt ones it+ * leaves to AltGr — are left un-prevented and bubble to the window dispatcher that+ * owns them.*/const platform = currentPlatform();term.attachCustomKeyEventHandler((event) => {@@ -413,13 +413,10 @@ export function TerminalView({}const action = terminalKeyAction(event, keymap(), platform, {canClose: callbacks.current.onCloseRequest !== undefined,- hasHandler: hasCommandHandler,});switch (action) {case "shell":return true;- case "skip-shell":- return false;case "consume":event.preventDefault();event.stopPropagation();diff --git a/packages/web/src/lib/shortcuts/chord.ts b/packages/web/src/lib/shortcuts/chord.tsindex 7e3a2b6f..beaf5e78 100644--- a/packages/web/src/lib/shortcuts/chord.ts+++ b/packages/web/src/lib/shortcuts/chord.ts@@ -109,6 +109,9 @@ export function codeFromKey(key: string): string {*/export function chordOf(e: KeyLike, platform: Platform): Chord | null {if (e.isComposing === true) return null;+ // AltGr is typing: Windows reports it as Ctrl+Alt on the character it produces (AltGr+S is+ // `ś` on the Polish layout), so that keydown is not a chord however it reads.+ if (e.altGraph === true || e.getModifierState?.("AltGraph") === true) return null;const code = e.code !== "" ? e.code : codeFromKey(e.key);if (code === "" || isModifierCode(code)) return null;if (platform === "mac") {diff --git a/packages/web/src/lib/shortcuts/dispatcher.ts b/packages/web/src/lib/shortcuts/dispatcher.tsindex 35b03e95..e2fa76b1 100644--- a/packages/web/src/lib/shortcuts/dispatcher.ts+++ b/packages/web/src/lib/shortcuts/dispatcher.ts@@ -48,13 +48,28 @@ export function runCommand(id: CommandId): boolean {return false;}+let blocker: (() => boolean) | null = null;++/**+ * Installs the predicate that suspends global commands: while a dialog or a menu is open (the+ * Esc-layer stack in components/ui/modal.tsx), a command must not run behind it — ⌥⌘S would open+ * the sidebar search under the overlay and pull focus out of the dialog. The store stays free of+ * React, so the layer owner installs the predicate itself at module scope.+ */+export function setShortcutBlocker(fn: (() => boolean) | null): void {+ blocker = fn;+}+/*** The window's keydown listener. A held chord auto-repeats: a repeat of a command that has a* handler is kept from the browser's own action (a binding on ⌘P would print from the first- * repeat on) but does not run the command again, so a held ⌥⌘1 toggles the sidebar once.+ * repeat on) but does not run the command again, so a held ⌥⌘1 toggles the sidebar once. Behind+ * an open dialog every key is left alone, so the dialog's own keys (and the browser's) work as if+ * nothing were bound.*/export function handleShortcutKeydown(event: KeyboardEvent): void {if (event.defaultPrevented) return;+ if (blocker?.() === true) return;const id = matchShortcut(event, keymap(), ["global"], currentPlatform());if (id === null) return;if (event.repeat) {diff --git a/packages/web/src/lib/shortcuts/registry.ts b/packages/web/src/lib/shortcuts/registry.tsindex d05e5938..58fdc1df 100644--- a/packages/web/src/lib/shortcuts/registry.ts+++ b/packages/web/src/lib/shortcuts/registry.ts@@ -21,6 +21,41 @@ export const SHORTCUT_COMMANDS: readonly ShortcutCommand[] = [// Mod+P is the browser's Print. On macOS this takes over Chrome's ⌥⌘P (Page Setup).defaults: { default: "Mod+Alt+KeyP" },},+ {+ id: "sessions.search",+ scope: "global",+ group: "general",+ // Mod+K is the browser's web search.+ defaults: { default: "Mod+Alt+KeyS" },+ },+ {+ id: "chat.new",+ scope: "global",+ group: "general",+ // Mod+N opens a browser window. On macOS this takes over Chrome's ⌥⌘N (split view).+ defaults: { default: "Mod+Alt+KeyN" },+ },+ {+ id: "sidebar.toggle",+ scope: "global",+ group: "panels",+ // Mod+B is Firefox's bookmarks sidebar; the three panel toggles count Mod+Alt+1 to 3.+ defaults: { default: "Mod+Alt+Digit1" },+ },+ {+ id: "dock.toggleRight",+ scope: "global",+ group: "panels",+ // Mod+Alt+B is Chrome's bookmark manager on macOS.+ defaults: { default: "Mod+Alt+Digit2" },+ },+ {+ id: "dock.toggleBottom",+ scope: "global",+ group: "panels",+ // Mod+J opens the browser's downloads.+ defaults: { default: "Mod+Alt+Digit3" },+ },{id: "terminal.toggle",scope: "global",@@ -28,6 +63,13 @@ export const SHORTCUT_COMMANDS: readonly ShortcutCommand[] = [// ⌃` on macOS too: ⌘` is macOS's own window cycling, and VS Code and Codex use ⌃` there.defaults: { default: "Ctrl+Backquote" },},+ {+ id: "terminal.new",+ scope: "global",+ group: "terminal",+ // VS Code's new-terminal chord, literal Control for the same reason as the toggle.+ defaults: { default: "Ctrl+Shift+Backquote" },+ },{id: "terminal.close",scope: "terminal",diff --git a/packages/web/src/lib/shortcuts/terminal-keys.ts b/packages/web/src/lib/shortcuts/terminal-keys.tsindex 380da086..1d95eac3 100644--- a/packages/web/src/lib/shortcuts/terminal-keys.ts+++ b/packages/web/src/lib/shortcuts/terminal-keys.ts@@ -1,27 +1,30 @@/*** What a focused terminal does with a keydown after the clipboard keys have had their turn.- * Pure: the surface passes what it knows (whether it offers a close, which global commands have a- * handler) and acts on the answer: the close chord (⌃⌥` / Ctrl+Alt+` by default) closes while- * Ctrl+W reaches readline; the terminal toggle pressed inside xterm runs without reaching the- * pty; a chord nothing answers (Ctrl+Alt+P before the palette exists) is the shell's.+ * Pure: the surface passes what it knows (whether it offers a close) and acts on the answer.+ *+ * The shell keeps every key xterm would send it, so an app command bound to one yields to the+ * shell while a terminal has focus: Ctrl+W stays readline's delete-word and Ctrl+B tmux's prefix,+ * and on Linux a Ctrl+Alt chord reaches the shell as Meta (Ctrl+Alt+1 arrives as Esc 1). The app+ * commands still reachable from a focused terminal are the ones xterm sends nothing for and so+ * never cancels — Ctrl+` and Ctrl+Shift+` (the terminal toggle and new terminal), every ⌘ chord+ * on a Mac, and on Windows a Ctrl+Alt chord on a character key, which xterm leaves to AltGr — and+ * those bubble to the window dispatcher on their own. The one terminal-scoped command,+ * `terminal.close` (⌃⌥` / Ctrl+Alt+` by default), is decided here, before xterm sees it.*/import { matchShortcut } from "./match";-import type { CommandId, KeyLike, Keymap, Platform } from "./types";+import type { KeyLike, Keymap, Platform } from "./types";export type TerminalKeyAction =/** Run the host's close: prevent, stop propagation, do not send to the shell. */| "close"/** A repeat of the close chord: prevent and stop as for "close", but run nothing. */| "consume"- /** A global command some surface answers: not the shell's, and left un-prevented so it bubbles to the window dispatcher. */- | "skip-shell"- /** Everything else, including a chord nothing answers: xterm sends it to the shell. */+ /** Everything else: xterm handles it, sending to the shell what it sends. */| "shell";export interface TerminalKeyHost {/** Whether this terminal offers a close at all (the dock tab and the standalone page do). */canClose: boolean;- hasHandler: (id: CommandId) => boolean;}export function terminalKeyAction(@@ -30,11 +33,7 @@ export function terminalKeyAction(platform: Platform,host: TerminalKeyHost,): TerminalKeyAction {- const command = matchShortcut(e, keymap, ["terminal", "global"], platform);- if (command === null) return "shell";- if (command === "terminal.close") {- if (!host.canClose) return "shell";- return e.repeat === true ? "consume" : "close";- }- return host.hasHandler(command) ? "skip-shell" : "shell";+ if (matchShortcut(e, keymap, ["terminal"], platform) !== "terminal.close") return "shell";+ if (!host.canClose) return "shell";+ return e.repeat === true ? "consume" : "close";}diff --git a/packages/web/src/lib/shortcuts/types.ts b/packages/web/src/lib/shortcuts/types.tsindex 75cb8572..96cf0c68 100644--- a/packages/web/src/lib/shortcuts/types.ts+++ b/packages/web/src/lib/shortcuts/types.ts@@ -27,7 +27,17 @@ export type ShortcutGroup = "general" | "panels" | "terminal" | "editor";* The rebindable commands. `palette.toggle` is owned by the command palette; its id and default* are reserved here so the settings page lists it before the palette lands.*/-export type CommandId = "palette.toggle" | "terminal.close" | "terminal.toggle" | "editor.save";+export type CommandId =+ | "palette.toggle"+ | "sessions.search"+ | "chat.new"+ | "sidebar.toggle"+ | "dock.toggleRight"+ | "dock.toggleBottom"+ | "terminal.toggle"+ | "terminal.new"+ | "terminal.close"+ | "editor.save";/*** One key combination. `code` is the `KeyboardEvent.code` of the non-modifier key ("KeyW",@@ -84,4 +94,8 @@ export interface KeyLike {shiftKey: boolean;repeat?: boolean;isComposing?: boolean;+ /** A DOM or React event's modifier query; the matcher asks it for AltGraph. */+ getModifierState?: (key: string) => boolean;+ /** Test literals set this directly; on a real event it is read through getModifierState. */+ altGraph?: boolean;}diff --git a/packages/web/src/lib/shortcuts/use-keymap.ts b/packages/web/src/lib/shortcuts/use-keymap.tsindex 5d099151..c131a756 100644--- a/packages/web/src/lib/shortcuts/use-keymap.ts+++ b/packages/web/src/lib/shortcuts/use-keymap.ts@@ -36,3 +36,9 @@ export function useShortcutLabel(id: CommandId): string | null {? null: formatChord(chord, currentPlatform(), keyboardLayout() ?? undefined);}++/** A control's tooltip naming the command's chord after its label — "Search sessions (⌥⌘S)" — or the label alone. */+export function useShortcutTitle(label: string, id: CommandId): string {+ const chord = useShortcutLabel(id);+ return chord === null ? label : `${label} (${chord})`;+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 87b6de9e..2055595e 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -142,7 +142,13 @@ export const en: Strings = {shortcuts: {commands: {"palette.toggle": "Command palette",+ "sessions.search": "Search sessions",+ "chat.new": "New chat",+ "sidebar.toggle": "Show or hide the sidebar",+ "dock.toggleRight": "Show or hide the right sidebar",+ "dock.toggleBottom": "Show or hide the bottom panel","terminal.toggle": "Show or hide the terminal",+ "terminal.new": "New terminal","terminal.close": "Close the focused terminal","editor.save": "Save",},diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex cf0a3cf0..ba12250e 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -164,7 +164,13 @@ export const zh = {shortcuts: {commands: {"palette.toggle": "命令面板",+ "sessions.search": "搜索会话",+ "chat.new": "新建对话",+ "sidebar.toggle": "显示或隐藏侧栏",+ "dock.toggleRight": "显示或隐藏右侧栏",+ "dock.toggleBottom": "显示或隐藏下侧栏","terminal.toggle": "显示或隐藏终端",+ "terminal.new": "新建终端","terminal.close": "关闭当前终端","editor.save": "保存",},diff --git a/packages/web/test/shortcuts-dispatcher.test.ts b/packages/web/test/shortcuts-dispatcher.test.tsindex 4dba2d1b..504d5451 100644--- a/packages/web/test/shortcuts-dispatcher.test.ts+++ b/packages/web/test/shortcuts-dispatcher.test.ts@@ -10,6 +10,7 @@ import {hasCommandHandler,onCommand,runCommand,+ setShortcutBlocker,} from "../src/lib/shortcuts/dispatcher";import { setPlatformForTests } from "../src/lib/shortcuts/platform";import { configureKeybindingsStoreForTests } from "../src/lib/shortcuts/store";@@ -45,6 +46,7 @@ beforeEach(() => {afterEach(() => {for (const off of unregisters.splice(0)) off();+ setShortcutBlocker(null);setPlatformForTests(null);configureKeybindingsStoreForTests({ storage: null, layout: null });});@@ -113,4 +115,16 @@ describe("the window listener", () => {fire({ code: "Backquote", key: "`", ctrlKey: true, defaultPrevented: true });expect(toggled).toBe(0);});++ it("leaves every key alone while a dialog or menu is open", () => {+ let toggled = 0;+ unregisters.push(onCommand("terminal.toggle", () => void toggled++));+ let open = true;+ setShortcutBlocker(() => open);+ expect(fire({ code: "Backquote", key: "`", ctrlKey: true }).defaultPrevented).toBe(false);+ expect(toggled).toBe(0);+ open = false;+ expect(fire({ code: "Backquote", key: "`", ctrlKey: true }).defaultPrevented).toBe(true);+ expect(toggled).toBe(1);+ });});diff --git a/packages/web/test/shortcuts-match.test.ts b/packages/web/test/shortcuts-match.test.tsindex ed4d8a32..0a05d128 100644--- a/packages/web/test/shortcuts-match.test.ts+++ b/packages/web/test/shortcuts-match.test.ts@@ -170,3 +170,82 @@ describe("layout relocation", () => {expect(relocateChord(parseChord("F5")!, dvorak).code).toBe("F5");});});++describe("the six panel and navigation commands", () => {+ const cases: Array<[CommandId, Partial<KeyLike> & { code: string }]> = [+ ["sessions.search", { code: "KeyS", altKey: true }],+ ["chat.new", { code: "KeyN", altKey: true }],+ ["sidebar.toggle", { code: "Digit1", altKey: true }],+ ["dock.toggleRight", { code: "Digit2", altKey: true }],+ ["dock.toggleBottom", { code: "Digit3", altKey: true }],+ ];++ it("bind with Mod+Alt: ⌥⌘ on a Mac, Ctrl+Alt elsewhere", () => {+ for (const [id, init] of cases) {+ expect(matchShortcut(key({ ...init, metaKey: true }), defaults("mac"), ALL, "mac"), id).toBe(+ id,+ );+ expect(+ matchShortcut(key({ ...init, ctrlKey: true }), defaults("mac"), ALL, "mac"),+ id,+ ).toBeNull();+ expect(+ matchShortcut(key({ ...init, ctrlKey: true }), defaults("windows"), ALL, "windows"),+ id,+ ).toBe(id);+ expect(+ matchShortcut(key({ ...init, ctrlKey: true }), defaults("linux"), ALL, "linux"),+ id,+ ).toBe(id);+ }+ });++ it("reads an AltGr character as typing, not as Mod+Alt: `ś` stays typable on Polish Windows", () => {+ const altGr = key({ code: "KeyS", key: "ś", ctrlKey: true, altKey: true, altGraph: true });+ expect(matchShortcut(altGr, defaults("windows"), ALL, "windows")).toBeNull();+ expect(+ matchShortcut(+ key({+ code: "KeyS",+ key: "ś",+ ctrlKey: true,+ altKey: true,+ getModifierState: (k) => k === "AltGraph",+ }),+ defaults("windows"),+ ALL,+ "windows",+ ),+ ).toBeNull();+ // A real Ctrl+Alt+S still is the chord.+ expect(+ matchShortcut(+ key({ code: "KeyS", ctrlKey: true, altKey: true }),+ defaults("windows"),+ ALL,+ "windows",+ ),+ ).toBe("sessions.search");+ });++ it("opens a new terminal on Ctrl+Shift+` on every platform, like the toggle", () => {+ for (const platform of ["mac", "windows", "linux"] as const) {+ expect(+ matchShortcut(+ key({ code: "Backquote", ctrlKey: true, shiftKey: true }),+ defaults(platform),+ ALL,+ platform,+ ),+ ).toBe("terminal.new");+ }+ expect(+ matchShortcut(+ key({ code: "Backquote", metaKey: true, shiftKey: true }),+ defaults("mac"),+ ALL,+ "mac",+ ),+ ).toBeNull();+ });+});diff --git a/packages/web/test/shortcuts-registry.test.ts b/packages/web/test/shortcuts-registry.test.tsindex eeda8bfd..6560a6cf 100644--- a/packages/web/test/shortcuts-registry.test.ts+++ b/packages/web/test/shortcuts-registry.test.ts@@ -20,8 +20,8 @@ import { en } from "../src/lib/strings-en";import type { Chord, CommandId, Platform } from "../src/lib/shortcuts/types";const PLATFORMS: readonly Platform[] = ["mac", "windows", "linux"];-/** The id grammar the server enforces on `ui_prefs.keybindings`. */-const ID_RE = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+$/;+/** The id grammar the server enforces on `ui_prefs.keybindings` (services/keybindings.ts). */+const ID_RE = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;function defaultsFor(platform: Platform): Map<CommandId, Chord | null> {return new Map(SHORTCUT_COMMANDS.map((cmd) => [cmd.id, defaultChord(cmd, platform)]));@@ -62,7 +62,7 @@ describe("registry defaults", () => {(text) => typeof text === "string" && text.includes("Ctrl+"),),).map((cmd) => cmd.id);- expect(literalCtrl).toEqual(["terminal.toggle", "terminal.close"]);+ expect(literalCtrl).toEqual(["terminal.toggle", "terminal.new", "terminal.close"]);});it("puts no default on a browser-reserved chord", () => {@@ -76,9 +76,10 @@ describe("registry defaults", () => {});it("names every default that shares a chord with a browser function", () => {- // Save takes the browser's Save Page on purpose; on macOS Chrome binds ⌥⌘P to Page Setup.+ // Save takes the browser's Save Page on purpose; on macOS Chrome binds ⌥⌘P to Page Setup+ // and ⌥⌘N to split view.const expected: Record<Platform, CommandId[]> = {- mac: ["palette.toggle", "editor.save"],+ mac: ["palette.toggle", "chat.new", "editor.save"],windows: ["editor.save"],linux: ["editor.save"],};diff --git a/packages/web/test/shortcuts-section.test.ts b/packages/web/test/shortcuts-section.test.tsindex 31ea8473..56b4bab0 100644--- a/packages/web/test/shortcuts-section.test.ts+++ b/packages/web/test/shortcuts-section.test.ts@@ -55,11 +55,9 @@ describe("ShortcutsSection", () => {setActiveStrings(dict);const html = render();for (const cmd of SHORTCUT_COMMANDS) expect(html).toContain(dict.shortcuts.commands[cmd.id]);- for (const group of ["general", "terminal", "editor"] as const) {- expect(html).toContain(dict.shortcuts.groups[group]);+ for (const group of ["general", "panels", "terminal", "editor"] as const) {+ expect(count(html, `>${dict.shortcuts.groups[group]}<`)).toBe(1);}- // No command sits in the panels group yet, so its heading is not drawn.- expect(count(html, `>${dict.shortcuts.groups.panels}<`)).toBe(0);}});diff --git a/packages/web/test/terminal-keys.test.ts b/packages/web/test/terminal-keys.test.tsindex f167a64a..95c7392c 100644--- a/packages/web/test/terminal-keys.test.ts+++ b/packages/web/test/terminal-keys.test.ts@@ -1,8 +1,8 @@/*** The focused terminal's key decision (src/lib/shortcuts/terminal-keys.ts) as a table: the close* chord (⌃⌥` on a Mac, Ctrl+Alt+` elsewhere) closing while Ctrl+W reaches readline everywhere, the- * toggle skipping the shell, the unanswered chord reaching the shell, the missing-close fallback,- * and the repeat.+ * shell keeping every key xterm sends even when it is bound (the Ctrl+Alt defaults on Linux), the+ * missing-close fallback, and the repeat.*/import { describe, expect, it } from "vitest";import { SHORTCUT_COMMANDS, defaultChord } from "../src/lib/shortcuts/registry";@@ -19,7 +19,6 @@ function key(overrides: Partial<KeyLike> & { code: string }): KeyLike {const host = (overrides: Partial<TerminalKeyHost> = {}): TerminalKeyHost => ({canClose: true,- hasHandler: (id) => id === "terminal.toggle",...overrides,});@@ -69,19 +68,51 @@ describe("terminalKeyAction", () => {"shell",],["⌘W is not the close on a Mac", "mac", key({ code: "KeyW", metaKey: true }), host(), "shell"],+ // A bound app command's chord goes back to xterm, which sends the shell what it sends:+ // on Linux the Ctrl+Alt defaults reach the shell as Meta.[- "the toggle skips the shell everywhere",- "mac",- key({ code: "Backquote", ctrlKey: true }),+ "Ctrl+Alt+1 (sidebar.toggle) is the shell's on Linux",+ "linux",+ key({ code: "Digit1", ctrlKey: true, altKey: true }),host(),- "skip-shell",+ "shell",+ ],+ [+ "Ctrl+Alt+S (sessions.search) likewise",+ "linux",+ key({ code: "KeyS", ctrlKey: true, altKey: true }),+ host(),+ "shell",],+ // Chords xterm sends nothing for are handed back to xterm too; it leaves them+ // un-prevented and the window dispatcher runs them.[- "the toggle skips the shell on Linux",+ "Ctrl+` goes back to xterm, which sends nothing and lets it bubble","linux",key({ code: "Backquote", ctrlKey: true }),host(),- "skip-shell",+ "shell",+ ],+ [+ "Ctrl+Shift+` likewise",+ "mac",+ key({ code: "Backquote", ctrlKey: true, shiftKey: true }),+ host(),+ "shell",+ ],+ [+ "⌥⌘1 likewise on a Mac",+ "mac",+ key({ code: "Digit1", metaKey: true, altKey: true }),+ host(),+ "shell",+ ],+ [+ "Ctrl+Alt+3 likewise on Windows, where xterm leaves Ctrl+Alt to AltGr",+ "windows",+ key({ code: "Digit3", ctrlKey: true, altKey: true }),+ host(),+ "shell",],["an unanswered chord is the shell's (Ctrl+Alt+P before the palette)",@@ -98,13 +129,6 @@ describe("terminalKeyAction", () => {"shell",],["plain typing is the shell's", "mac", key({ code: "KeyW", key: "w" }), host(), "shell"],- [- "a plain Ctrl+C is the shell's",- "linux",- key({ code: "KeyC", ctrlKey: true }),- host(),- "shell",- ],["with no close on offer the chord goes to the shell","linux",@@ -119,13 +143,6 @@ describe("terminalKeyAction", () => {host(),"consume",],- [- "a held toggle still skips the shell (the dispatcher swallows the repeat)",- "linux",- key({ code: "Backquote", ctrlKey: true, repeat: true }),- host(),- "skip-shell",- ],];for (const [name, platform, e, h, expected] of table) {