diff --git a/apps/web/tests/expected/shortcuts-workspace/macos-defaults.expected.md b/apps/web/tests/expected/shortcuts-workspace/macos-defaults.expected.md index 380d3abc84..7bddffee98 100644 --- a/apps/web/tests/expected/shortcuts-workspace/macos-defaults.expected.md +++ b/apps/web/tests/expected/shortcuts-workspace/macos-defaults.expected.md @@ -7,84 +7,87 @@ - region "Application": - list: - listitem: - - text: Close current page or window - - button "Remove shortcut for Close current page or window" - - button "Edit shortcut for Close current page or window" - - button "Close current page or window ⌥ ⌘ W": ⌥ ⌘ W - - listitem: - - text: Refresh current page - - button "Edit shortcut for Refresh current page" - - button "Refresh current page No shortcut": No shortcut - - listitem: - - text: Toggle panel fullscreen - - button "Remove shortcut for Toggle panel fullscreen" - - button "Edit shortcut for Toggle panel fullscreen" - - button "Toggle panel fullscreen ⌥ ⌘ Enter": ⌥ ⌘ Enter - - listitem: - - text: Split - - button "Remove shortcut for Split" - - button "Edit shortcut for Split" - - button "Split ⌘ \\": ⌘ \ - - listitem: - - text: Archive session - - button "Remove shortcut for Archive session" - - button "Edit shortcut for Archive session" - - button "Archive session ⌥ ⌘ A": ⌥ ⌘ A - - listitem: - - text: Fork session - - button "Remove shortcut for Fork session" - - button "Edit shortcut for Fork session" - - button "Fork session ⇧ ⌘ F": ⇧ ⌘ F + - text: Open keyboard shortcuts + - button "Remove shortcut for Open keyboard shortcuts" + - button "Edit shortcut for Open keyboard shortcuts" + - button "Open keyboard shortcuts ⌘ /": ⌘ / - listitem: - text: New Session - button "Remove shortcut for New Session" - button "Edit shortcut for New Session" - button "New Session ⌥ ⌘ N": ⌥ ⌘ N - listitem: - - text: Rename session - - button "Remove shortcut for Rename session" - - button "Edit shortcut for Rename session" - - button "Rename session ⇧ ⌘ R": ⇧ ⌘ R + - text: Toggle left sidebar + - button "Remove shortcut for Toggle left sidebar" + - button "Edit shortcut for Toggle left sidebar" + - button "Toggle left sidebar ⌥ ⌘ B": ⌥ ⌘ B - listitem: - text: Search sessions - button "Remove shortcut for Search sessions" - button "Edit shortcut for Search sessions" - button "Search sessions ⌥ ⌘ K": ⌥ ⌘ K + - listitem: + - text: Add workspace + - button "Remove shortcut for Add workspace" + - button "Edit shortcut for Add workspace" + - button "Add workspace ⌥ ⌘ O": ⌥ ⌘ O + - listitem: + - text: Rename session + - button "Remove shortcut for Rename session" + - button "Edit shortcut for Rename session" + - button "Rename session ⇧ ⌘ R": ⇧ ⌘ R + - listitem: + - text: Fork session + - button "Remove shortcut for Fork session" + - button "Edit shortcut for Fork session" + - button "Fork session ⇧ ⌘ F": ⇧ ⌘ F + - listitem: + - text: Archive session + - button "Remove shortcut for Archive session" + - button "Edit shortcut for Archive session" + - button "Archive session ⌥ ⌘ A": ⌥ ⌘ A - listitem: - text: Open settings - button "Remove shortcut for Open settings" - button "Edit shortcut for Open settings" - button "Open settings ⌘ ,": ⌘ , - - listitem: - - text: Open keyboard shortcuts - - button "Remove shortcut for Open keyboard shortcuts" - - button "Edit shortcut for Open keyboard shortcuts" - - button "Open keyboard shortcuts ⌘ /": ⌘ / - - listitem: - - text: Toggle left sidebar - - button "Remove shortcut for Toggle left sidebar" - - button "Edit shortcut for Toggle left sidebar" - - button "Toggle left sidebar ⌥ ⌘ B": ⌥ ⌘ B - listitem: - text: Toggle right sidebar - button "Remove shortcut for Toggle right sidebar" - button "Edit shortcut for Toggle right sidebar" - button "Toggle right sidebar ⇧ ⌘ B": ⇧ ⌘ B + - listitem: + - text: Workspace files + - button "Remove shortcut for Workspace files" + - button "Edit shortcut for Workspace files" + - button "Workspace files ⌥ ⌘ P": ⌥ ⌘ P - listitem: - text: New terminal - button "Remove shortcut for New terminal" - button "Edit shortcut for New terminal" - 'button "New terminal ⌃ `"': "⌃ `" - listitem: - - text: Add workspace - - button "Remove shortcut for Add workspace" - - button "Edit shortcut for Add workspace" - - button "Add workspace ⌥ ⌘ O": ⌥ ⌘ O + - text: Split + - button "Remove shortcut for Split" + - button "Edit shortcut for Split" + - button "Split ⌘ \\": ⌘ \ - listitem: - - text: Workspace files - - button "Remove shortcut for Workspace files" - - button "Edit shortcut for Workspace files" - - button "Workspace files ⌥ ⌘ P": ⌥ ⌘ P + - text: Toggle panel fullscreen + - button "Remove shortcut for Toggle panel fullscreen" + - button "Edit shortcut for Toggle panel fullscreen" + - button "Toggle panel fullscreen ⌥ ⌘ Enter": ⌥ ⌘ Enter + - listitem: + - text: Refresh current page + - button "Edit shortcut for Refresh current page" + - button "Refresh current page No shortcut": No shortcut + - listitem: + - text: Close current page or window + - button "Remove shortcut for Close current page or window" + - button "Edit shortcut for Close current page or window" + - button "Close current page or window ⌥ ⌘ W": ⌥ ⌘ W + - listitem: + - text: Stop generating + - button "Stop generating Esc Esc" [disabled]: Esc Esc - region "Message input": - heading "Message input" [level=3] - list: @@ -103,9 +106,6 @@ - listitem: - text: Open command menu - button "Open command menu /" [disabled]: / - - listitem: - - text: Stop generating - - button "Stop generating Esc Esc" [disabled]: Esc Esc - region "Menus and dialogs": - heading "Menus and dialogs" [level=3] - list: diff --git a/apps/web/tests/expected/shortcuts/en-US.expected.md b/apps/web/tests/expected/shortcuts/en-US.expected.md index 9c92e5ffe3..4460a24ce0 100644 --- a/apps/web/tests/expected/shortcuts/en-US.expected.md +++ b/apps/web/tests/expected/shortcuts/en-US.expected.md @@ -7,85 +7,88 @@ - region "Application": - list: - listitem: - - text: Close current page or window - - button "Remove shortcut for Close current page or window" - - button "Edit shortcut for Close current page or window" - - button "Close current page or window Ctrl + Alt + W": Ctrl + Alt + W - - listitem: - - text: Refresh current page - - button "Remove shortcut for Refresh current page" - - button "Edit shortcut for Refresh current page" - - button "Refresh current page Ctrl + Alt + R": Ctrl + Alt + R - - listitem: - - text: Toggle panel fullscreen - - button "Remove shortcut for Toggle panel fullscreen" - - button "Edit shortcut for Toggle panel fullscreen" - - button "Toggle panel fullscreen Ctrl + Alt + Enter": Ctrl + Alt + Enter - - listitem: - - text: Split - - button "Remove shortcut for Split" - - button "Edit shortcut for Split" - - button "Split Ctrl + \\": Ctrl + \ - - listitem: - - text: Archive session - - button "Remove shortcut for Archive session" - - button "Edit shortcut for Archive session" - - button "Archive session Ctrl + Alt + A": Ctrl + Alt + A - - listitem: - - text: Fork session - - button "Remove shortcut for Fork session" - - button "Edit shortcut for Fork session" - - button "Fork session Ctrl + Shift + F": Ctrl + Shift + F + - text: Open keyboard shortcuts + - button "Remove shortcut for Open keyboard shortcuts" + - button "Edit shortcut for Open keyboard shortcuts" + - button "Open keyboard shortcuts Ctrl + /": Ctrl + / - listitem: - text: New Session - button "Remove shortcut for New Session" - button "Edit shortcut for New Session" - button "New Session Ctrl + Alt + N": Ctrl + Alt + N - listitem: - - text: Rename session - - button "Remove shortcut for Rename session" - - button "Edit shortcut for Rename session" - - button "Rename session Ctrl + Shift + R": Ctrl + Shift + R + - text: Toggle left sidebar + - button "Remove shortcut for Toggle left sidebar" + - button "Edit shortcut for Toggle left sidebar" + - button "Toggle left sidebar Ctrl + Alt + B": Ctrl + Alt + B - listitem: - text: Search sessions - button "Remove shortcut for Search sessions" - button "Edit shortcut for Search sessions" - button "Search sessions Ctrl + Alt + K": Ctrl + Alt + K + - listitem: + - text: Add workspace + - button "Remove shortcut for Add workspace" + - button "Edit shortcut for Add workspace" + - button "Add workspace Ctrl + Alt + O": Ctrl + Alt + O + - listitem: + - text: Rename session + - button "Remove shortcut for Rename session" + - button "Edit shortcut for Rename session" + - button "Rename session Ctrl + Shift + R": Ctrl + Shift + R + - listitem: + - text: Fork session + - button "Remove shortcut for Fork session" + - button "Edit shortcut for Fork session" + - button "Fork session Ctrl + Shift + F": Ctrl + Shift + F + - listitem: + - text: Archive session + - button "Remove shortcut for Archive session" + - button "Edit shortcut for Archive session" + - button "Archive session Ctrl + Alt + A": Ctrl + Alt + A - listitem: - text: Open settings - button "Remove shortcut for Open settings" - button "Edit shortcut for Open settings" - button "Open settings Ctrl + ,": Ctrl + , - - listitem: - - text: Open keyboard shortcuts - - button "Remove shortcut for Open keyboard shortcuts" - - button "Edit shortcut for Open keyboard shortcuts" - - button "Open keyboard shortcuts Ctrl + /": Ctrl + / - - listitem: - - text: Toggle left sidebar - - button "Remove shortcut for Toggle left sidebar" - - button "Edit shortcut for Toggle left sidebar" - - button "Toggle left sidebar Ctrl + Alt + B": Ctrl + Alt + B - listitem: - text: Toggle right sidebar - button "Remove shortcut for Toggle right sidebar" - button "Edit shortcut for Toggle right sidebar" - button "Toggle right sidebar Ctrl + Shift + B": Ctrl + Shift + B + - listitem: + - text: Workspace files + - button "Remove shortcut for Workspace files" + - button "Edit shortcut for Workspace files" + - button "Workspace files Ctrl + Alt + P": Ctrl + Alt + P - listitem: - text: New terminal - button "Remove shortcut for New terminal" - button "Edit shortcut for New terminal" - 'button "New terminal Ctrl + `"': "Ctrl + `" - listitem: - - text: Add workspace - - button "Remove shortcut for Add workspace" - - button "Edit shortcut for Add workspace" - - button "Add workspace Ctrl + Alt + O": Ctrl + Alt + O + - text: Split + - button "Remove shortcut for Split" + - button "Edit shortcut for Split" + - button "Split Ctrl + \\": Ctrl + \ - listitem: - - text: Workspace files - - button "Remove shortcut for Workspace files" - - button "Edit shortcut for Workspace files" - - button "Workspace files Ctrl + Alt + P": Ctrl + Alt + P + - text: Toggle panel fullscreen + - button "Remove shortcut for Toggle panel fullscreen" + - button "Edit shortcut for Toggle panel fullscreen" + - button "Toggle panel fullscreen Ctrl + Alt + Enter": Ctrl + Alt + Enter + - listitem: + - text: Refresh current page + - button "Remove shortcut for Refresh current page" + - button "Edit shortcut for Refresh current page" + - button "Refresh current page Ctrl + Alt + R": Ctrl + Alt + R + - listitem: + - text: Close current page or window + - button "Remove shortcut for Close current page or window" + - button "Edit shortcut for Close current page or window" + - button "Close current page or window Ctrl + Alt + W": Ctrl + Alt + W + - listitem: + - text: Stop generating + - button "Stop generating Esc Esc" [disabled]: Esc Esc - region "Message input": - heading "Message input" [level=3] - list: @@ -104,9 +107,6 @@ - listitem: - text: Open command menu - button "Open command menu /" [disabled]: / - - listitem: - - text: Stop generating - - button "Stop generating Esc Esc" [disabled]: Esc Esc - region "Menus and dialogs": - heading "Menus and dialogs" [level=3] - list: diff --git a/apps/web/tests/expected/shortcuts/zh-CN.expected.md b/apps/web/tests/expected/shortcuts/zh-CN.expected.md index 1a118a48d0..8fa16c3e99 100644 --- a/apps/web/tests/expected/shortcuts/zh-CN.expected.md +++ b/apps/web/tests/expected/shortcuts/zh-CN.expected.md @@ -7,84 +7,87 @@ - region "应用操作": - list: - listitem: - - text: 关闭当前页面/窗口 - - button "移除关闭当前页面/窗口快捷键" - - button "修改关闭当前页面/窗口快捷键" - - button "关闭当前页面/窗口 ⌥ ⌘ W": ⌥ ⌘ W - - listitem: - - text: 刷新当前页面 - - button "修改刷新当前页面快捷键" - - button "刷新当前页面 暂无快捷键": 暂无快捷键 - - listitem: - - text: 面板全屏/退出全屏 - - button "移除面板全屏/退出全屏快捷键" - - button "修改面板全屏/退出全屏快捷键" - - button "面板全屏/退出全屏 ⌥ ⌘ Enter": ⌥ ⌘ Enter - - listitem: - - text: 分栏 - - button "移除分栏快捷键" - - button "修改分栏快捷键" - - button "分栏 ⌘ \\": ⌘ \ - - listitem: - - text: 归档会话 - - button "移除归档会话快捷键" - - button "修改归档会话快捷键" - - button "归档会话 ⌥ ⌘ A": ⌥ ⌘ A - - listitem: - - text: 分叉会话 - - button "移除分叉会话快捷键" - - button "修改分叉会话快捷键" - - button "分叉会话 ⇧ ⌘ F": ⇧ ⌘ F + - text: 快捷键速查 + - button "移除快捷键速查快捷键" + - button "修改快捷键速查快捷键" + - button "快捷键速查 ⌘ /": ⌘ / - listitem: - text: 新会话 - button "移除新会话快捷键" - button "修改新会话快捷键" - button "新会话 ⌥ ⌘ N": ⌥ ⌘ N - listitem: - - text: 重命名会话 - - button "移除重命名会话快捷键" - - button "修改重命名会话快捷键" - - button "重命名会话 ⇧ ⌘ R": ⇧ ⌘ R + - text: 展开/收起左侧栏 + - button "移除展开/收起左侧栏快捷键" + - button "修改展开/收起左侧栏快捷键" + - button "展开/收起左侧栏 ⌥ ⌘ B": ⌥ ⌘ B - listitem: - text: 搜索会话 - button "移除搜索会话快捷键" - button "修改搜索会话快捷键" - button "搜索会话 ⌥ ⌘ K": ⌥ ⌘ K + - listitem: + - text: 添加工作区 + - button "移除添加工作区快捷键" + - button "修改添加工作区快捷键" + - button "添加工作区 ⌥ ⌘ O": ⌥ ⌘ O + - listitem: + - text: 重命名会话 + - button "移除重命名会话快捷键" + - button "修改重命名会话快捷键" + - button "重命名会话 ⇧ ⌘ R": ⇧ ⌘ R + - listitem: + - text: 分叉会话 + - button "移除分叉会话快捷键" + - button "修改分叉会话快捷键" + - button "分叉会话 ⇧ ⌘ F": ⇧ ⌘ F + - listitem: + - text: 归档会话 + - button "移除归档会话快捷键" + - button "修改归档会话快捷键" + - button "归档会话 ⌥ ⌘ A": ⌥ ⌘ A - listitem: - text: 打开设置 - button "移除打开设置快捷键" - button "修改打开设置快捷键" - button "打开设置 ⌘ ,": ⌘ , - - listitem: - - text: 快捷键速查 - - button "移除快捷键速查快捷键" - - button "修改快捷键速查快捷键" - - button "快捷键速查 ⌘ /": ⌘ / - - listitem: - - text: 展开/收起左侧栏 - - button "移除展开/收起左侧栏快捷键" - - button "修改展开/收起左侧栏快捷键" - - button "展开/收起左侧栏 ⌥ ⌘ B": ⌥ ⌘ B - listitem: - text: 展开/收起右侧栏 - button "移除展开/收起右侧栏快捷键" - button "修改展开/收起右侧栏快捷键" - button "展开/收起右侧栏 ⇧ ⌘ B": ⇧ ⌘ B + - listitem: + - text: 工作区文件 + - button "移除工作区文件快捷键" + - button "修改工作区文件快捷键" + - button "工作区文件 ⌥ ⌘ P": ⌥ ⌘ P - listitem: - text: 新建终端 - button "移除新建终端快捷键" - button "修改新建终端快捷键" - 'button "新建终端 ⌃ `"': "⌃ `" - listitem: - - text: 添加工作区 - - button "移除添加工作区快捷键" - - button "修改添加工作区快捷键" - - button "添加工作区 ⌥ ⌘ O": ⌥ ⌘ O + - text: 分栏 + - button "移除分栏快捷键" + - button "修改分栏快捷键" + - button "分栏 ⌘ \\": ⌘ \ - listitem: - - text: 工作区文件 - - button "移除工作区文件快捷键" - - button "修改工作区文件快捷键" - - button "工作区文件 ⌥ ⌘ P": ⌥ ⌘ P + - text: 面板全屏/退出全屏 + - button "移除面板全屏/退出全屏快捷键" + - button "修改面板全屏/退出全屏快捷键" + - button "面板全屏/退出全屏 ⌥ ⌘ Enter": ⌥ ⌘ Enter + - listitem: + - text: 刷新当前页面 + - button "修改刷新当前页面快捷键" + - button "刷新当前页面 暂无快捷键": 暂无快捷键 + - listitem: + - text: 关闭当前页面/窗口 + - button "移除关闭当前页面/窗口快捷键" + - button "修改关闭当前页面/窗口快捷键" + - button "关闭当前页面/窗口 ⌥ ⌘ W": ⌥ ⌘ W + - listitem: + - text: 停止生成 + - button "停止生成 Esc Esc" [disabled]: Esc Esc - region "消息输入": - heading "消息输入" [level=3] - list: @@ -103,9 +106,6 @@ - listitem: - text: 打开命令菜单 - button "打开命令菜单 /" [disabled]: / - - listitem: - - text: 停止生成 - - button "停止生成 Esc Esc" [disabled]: Esc Esc - region "菜单与弹层": - heading "菜单与弹层" [level=3] - list: diff --git a/apps/web/tests/shortcuts.e2e.ts b/apps/web/tests/shortcuts.e2e.ts index 9c63649613..b25d56f07a 100644 --- a/apps/web/tests/shortcuts.e2e.ts +++ b/apps/web/tests/shortcuts.e2e.ts @@ -48,6 +48,12 @@ describe('web e2e: shortcut reference', () => { expect(await dialog.boundingBox()).toMatchObject({ width: 480, height: 600 }) expect(await dialog.getByRole('search').boundingBox()).toMatchObject({ width: 432, height: 36 }) const rows = dialog.getByRole('listitem') + const stopRow = dialog.getByRole('region', { name: locale === 'zh-CN' ? '应用操作' : 'Application', exact: true }) + .getByRole('listitem').last() + await stopRow.getByText(locale === 'zh-CN' ? '停止生成' : 'Stop generating', { exact: true }).waitFor() + const stopButtons = stopRow.getByRole('button') + expect(await stopButtons.count()).toBe(1) + expect(await stopButtons.isDisabled()).toBe(true) expect(new Set(await rows.evaluateAll(items => items.map(row => row.getBoundingClientRect().height)))) .toEqual(new Set([42])) expect(await rows.evaluateAll(items => items.every(row => row.getBoundingClientRect().height >= 42 diff --git a/packages/client/shortcuts/README.i18n.yaml b/packages/client/shortcuts/README.i18n.yaml index 6d1b4d3260..543902907b 100644 --- a/packages/client/shortcuts/README.i18n.yaml +++ b/packages/client/shortcuts/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/shortcuts/README.md -README.md: c9c5fe591aed234f70debb0b59e686550d584c0d -README.zh.md: 64e1bd9835c025eb1fb0378582fe66071375b72c +README.md: ae80d40ef3924769c6564da9448fab1809f8535b +README.zh.md: a8761fbef25bb111438a2ed4c188600c4ca6a97c diff --git a/packages/client/shortcuts/README.md b/packages/client/shortcuts/README.md index c9c5fe591a..ae80d40ef3 100644 --- a/packages/client/shortcuts/README.md +++ b/packages/client/shortcuts/README.md @@ -29,7 +29,7 @@ Windows uses ` + ` between modifiers and the first ordinary key. Two simultaneou The Web app bundle mounts this package automatically. Feature plugins register commands through `ctx.shortcuts` inside `ctx.effect()`. Each command declares defaults for explicit `desktop:macos`, `desktop:windows`, `desktop:linux`, `web:macos`, `web:windows`, and `web:linux` profiles; an omitted profile is unbound. The service accepts physical `code` values, expands `primary` to the device modifier, and rejects duplicate ids and overlapping default combinations across supported profiles. Labels, keycaps, modified flags, and binding conflicts share one observable catalog. Command owners resolve the current target before executing an action. -Feature plugins contribute read-only sequences through `registerFixed()` and observe locally arbitrated input through `observeFixedInput()`. Fixed rows follow the owning registration and locale. Each action declares at least one physical combination and has no saved overrides. These combinations participate in conflict checks and cannot be assigned to editable commands. The Host's `stopSequenceMs` setting controls the maximum double-Escape interval, defaults to 500 milliseconds, and accepts integers from 1 to 2,147,483,646 so expiry stays within the browser timer limit; pages adopt the validated value on load. +Feature plugins contribute read-only sequences through `registerFixed()` and observe locally arbitrated input through `observeFixedInput()`. Fixed rows follow the owning registration and locale; owners may use the `application` display group without making the action editable. Each action declares at least one physical combination and has no saved overrides. These combinations participate in conflict checks and cannot be assigned to editable commands. The Host's `stopSequenceMs` setting controls the maximum double-Escape interval, defaults to 500 milliseconds, and accepts integers from 1 to 2,147,483,646 so expiry stays within the browser timer limit; pages adopt the validated value on load. Preferences store only overrides: a missing command inherits its default, `null` clears its binding, and restoring a default removes its override. Restore All affects only the current runtime/platform profile. Web uses origin-local `dsh.keybindings.v1` storage; Desktop uses Electron's device-local `userData/keybindings.json`, independently of Harness home and workspace settings. The schema version is independent of Session data. macOS and Windows Desktop read version 1 without rewriting it and save version 2 on the next successful edit; version 2 adds optional `secondCode`. Web and Linux retain their existing binding restrictions. diff --git a/packages/client/shortcuts/README.zh.md b/packages/client/shortcuts/README.zh.md index 64e1bd9835..a8761fbef2 100644 --- a/packages/client/shortcuts/README.zh.md +++ b/packages/client/shortcuts/README.zh.md @@ -29,7 +29,7 @@ Windows 在修饰键之间及第一个普通键之前使用 ` + `。Windows 和 Web 应用 bundle 自动挂载此包。功能插件在 `ctx.effect()` 中通过 `ctx.shortcuts` 注册命令。每个命令为 `desktop:macos`、`desktop:windows`、`desktop:linux`、`web:macos`、`web:windows` 和 `web:linux` 显式声明默认值;省略的配置不绑定按键。服务接收物理 `code`,按设备展开 `primary`,并拒绝重复 ID 和任一支持配置中重叠的默认键位。同一可观察目录提供名称、键帽、已修改标记和键位冲突。命令 owner 在执行操作前解析当前目标。 -功能插件通过 `registerFixed()` 贡献只读序列,通过 `observeFixedInput()` 观察局部控件处理后的输入。固定操作行随所属注册和语言变化。每个操作至少声明一个物理按键组合,不保存覆盖配置。这些组合参与冲突校验,不能分配给可编辑命令。Host 的 `stopSequenceMs` 配置控制连续两次 Esc 的最大间隔,默认为 500 毫秒,只接受 1 至 2,147,483,646 的整数,确保过期计时不超过浏览器定时器上限;页面加载时采用已校验的值。 +功能插件通过 `registerFixed()` 贡献只读序列,通过 `observeFixedInput()` 观察局部控件处理后的输入。固定操作行随所属注册和语言变化;owner 可使用 `application` 展示分组,操作仍不可编辑。每个操作至少声明一个物理按键组合,不保存覆盖配置。这些组合参与冲突校验,不能分配给可编辑命令。Host 的 `stopSequenceMs` 配置控制连续两次 Esc 的最大间隔,默认为 500 毫秒,只接受 1 至 2,147,483,646 的整数,确保过期计时不超过浏览器定时器上限;页面加载时采用已校验的值。 偏好只保存覆盖:缺少命令表示继承默认,`null` 表示清除绑定,恢复默认则删除覆盖。全部恢复只影响当前运行端/平台配置。Web 使用同 origin 的 `dsh.keybindings.v1` 存储;Desktop 使用 Electron 设备本地的 `userData/keybindings.json`,与 Harness home 和工作区设置独立。其 schema 版本与 Session 数据无关。 macOS 和 Windows Desktop 读取版本 1 时不重写,在下次成功编辑时保存为版本 2;版本 2 增加可选的 `secondCode`。Web 和 Linux 保留原有绑定限制。 diff --git a/packages/client/shortcuts/src/client/types.ts b/packages/client/shortcuts/src/client/types.ts index a530ce549d..565b907694 100644 --- a/packages/client/shortcuts/src/client/types.ts +++ b/packages/client/shortcuts/src/client/types.ts @@ -69,7 +69,7 @@ export interface ShortcutFixedCommand { readonly keys: readonly string[] /** One or more physical combinations reserved by this action, including individual steps of a sequence. */ readonly bindings: readonly [ShortcutBinding, ...ShortcutBinding[]] - readonly group: 'input' | 'menus' | 'approval' + readonly group: 'application' | 'input' | 'menus' | 'approval' } /** Localized fixed-action row; its key sequence is not an editable binding. */ export interface ShortcutFixedCatalogEntry { diff --git a/packages/client/shortcuts/tests/fixed-input.client.spec.ts b/packages/client/shortcuts/tests/fixed-input.client.spec.ts index 07b2b93692..71eedaae0c 100644 --- a/packages/client/shortcuts/tests/fixed-input.client.spec.ts +++ b/packages/client/shortcuts/tests/fixed-input.client.spec.ts @@ -96,9 +96,9 @@ it('releases listeners, modal observation, and pending local-input resets on dis it('publishes fixed reservations and removes them with their owning registration', () => { const registry = new ShortcutRegistry('web', 'windows') let label = 'Stop reply' - const command: ShortcutFixedCommand = { id: 'response.stop' as ShortcutCommandId, label: () => label, keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'input' } + const command: ShortcutFixedCommand = { id: 'response.stop' as ShortcutCommandId, label: () => label, keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'application' } const off = registry.registerFixed(command) - expect(registry.fixedCatalog.getSnapshot()).toEqual([{ id: 'response.stop', label, keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'input' }]) + expect(registry.fixedCatalog.getSnapshot()).toEqual([{ id: 'response.stop', label, keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'application' }]) expect(registry.definitions()).toEqual([{ id: 'response.stop', defaults: {}, fixed: [{ code: 'Escape', modifiers: [] }] }]) expect(() => registry.registerFixed(command)).toThrow('Duplicate') expect(() => registry.register({ ...command, aliases: [], defaults: {}, regions: [], modals: [], resolve: () => ({ status: 'pass' }) })).toThrow('Duplicate') diff --git a/packages/client/ui-conversation/README.i18n.yaml b/packages/client/ui-conversation/README.i18n.yaml index 7a78efe23c..e78203f796 100644 --- a/packages/client/ui-conversation/README.i18n.yaml +++ b/packages/client/ui-conversation/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-conversation/README.md -README.md: 2ee80ef18514ec0e6ecae1c08367839d7a3330a8 -README.zh.md: dd8d2ef628045cc63876d491f233c2179556917b +README.md: 56235b5b1fe106de4295e705bbed101cda5c0431 +README.zh.md: de4c6949c3a8897a942169a2fb70229e9cdeaace diff --git a/packages/client/ui-conversation/README.md b/packages/client/ui-conversation/README.md index 2ee80ef185..56235b5b1f 100644 --- a/packages/client/ui-conversation/README.md +++ b/packages/client/ui-conversation/README.md @@ -84,7 +84,7 @@ File chips and editable skill references share a whole-reference hover backgroun When another writer owns the Session, the send-error toast asks the user to quit other running DSH instances and retry. -Two independent Escape presses in the focused Chat or Composer stop its current running turn and preserve queued messages. The interval comes from the shortcuts plugin’s `stopSequenceMs` configuration (500 ms by default). A menu, approval, modal, terminal, embedded webpage, composition, repeated key, changed input region, Session or turn breaks the sequence. The shortcut uses the same scoped cancellation as the Stop button. Its fixed-action registration reserves plain Escape against editable shortcuts and supplies the `Esc Esc` sequence shown in the Stop button’s hover and keyboard-focus tooltip. +Two independent Escape presses in the focused Chat or Composer stop its current running turn and preserve queued messages. The interval comes from the shortcuts plugin’s `stopSequenceMs` configuration (500 ms by default). A menu, approval, modal, terminal, embedded webpage, composition, repeated key, changed input region, Session or turn breaks the sequence. The shortcut uses the same scoped cancellation as the Stop button. The plugin registers Stop as a fixed action in the `application` display group. Its registration reserves plain Escape against editable shortcuts and supplies the `Esc Esc` sequence shown in the Stop button’s hover and keyboard-focus tooltip. ## Temporary composer entries diff --git a/packages/client/ui-conversation/README.zh.md b/packages/client/ui-conversation/README.zh.md index dd8d2ef628..de4c6949c3 100644 --- a/packages/client/ui-conversation/README.zh.md +++ b/packages/client/ui-conversation/README.zh.md @@ -84,7 +84,7 @@ Send 和 Stop 按钮禁用时不显示提示气泡,轮次结束后由 Stop 切 当会话被其他写句柄占用时,发送失败的 toast 提示用户退出其他正在运行的 DSH 后重试。 -在获得焦点的 Chat 或 Composer 中连续独立按下两次 Esc,可停止当前运行轮次并保留排队消息。间隔由 shortcuts 插件的 `stopSequenceMs` 配置决定,默认 500 ms。菜单、审批、模态层、终端、内嵌网页、输入法、重复按键,以及输入区域、Session 或轮次变化会清空序列。快捷键与 Stop 按钮调用同一作用域取消操作。固定操作注册使普通 Esc 不能分配给可编辑快捷键,并为 Stop 按钮的悬停和键盘聚焦提示提供 `Esc Esc` 序列。 +在获得焦点的 Chat 或 Composer 中连续独立按下两次 Esc,可停止当前运行轮次并保留排队消息。间隔由 shortcuts 插件的 `stopSequenceMs` 配置决定,默认 500 ms。菜单、审批、模态层、终端、内嵌网页、输入法、重复按键,以及输入区域、Session 或轮次变化会清空序列。快捷键与 Stop 按钮调用同一作用域取消操作。插件将 Stop 注册为 `application` 展示分组中的固定操作。该注册使普通 Esc 不能分配给可编辑快捷键,并为 Stop 按钮的悬停和键盘聚焦提示提供 `Esc Esc` 序列。 ## 临时 composer entry diff --git a/packages/client/ui-conversation/src/client/apply.ts b/packages/client/ui-conversation/src/client/apply.ts index a4fc7eed43..15e05e3fc7 100644 --- a/packages/client/ui-conversation/src/client/apply.ts +++ b/packages/client/ui-conversation/src/client/apply.ts @@ -256,7 +256,7 @@ export function apply(ctx: Context, config: Config = Config({})): void { ), 'ui-conversation: fixed stop input') scope.effect(() => { const command: ShortcutFixedCommand = { - id: 'response.stop' as ShortcutCommandId, label: () => t('input.stop'), keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'input', + id: 'response.stop' as ShortcutCommandId, label: () => t('input.stop'), keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'application', } const dispose = scope.shortcuts.registerFixed(command) stopShortcut.set(command.keys) diff --git a/packages/client/ui-shortcuts/README.i18n.yaml b/packages/client/ui-shortcuts/README.i18n.yaml index 00810621ab..66aec728aa 100644 --- a/packages/client/ui-shortcuts/README.i18n.yaml +++ b/packages/client/ui-shortcuts/README.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write packages/client/ui-shortcuts/README.md -README.md: a8bef7d9d41353eda7b86127d641a123534e4128 -README.zh.md: 77bcace81b28da5cc1ec66fb30e05ca9abb3c5ba +README.md: 6362062438818802041d36bf59fc3e43c291a4f0 +README.zh.md: 5b243a8b461d7b550f7f2a597f58588458387f58 diff --git a/packages/client/ui-shortcuts/README.md b/packages/client/ui-shortcuts/README.md index a8bef7d9d4..6362062438 100644 --- a/packages/client/ui-shortcuts/README.md +++ b/packages/client/ui-shortcuts/README.md @@ -9,7 +9,7 @@ English | [中文](README.zh.md) ## Summary -Browse the commands available in the current window and find them by action, English alias, or key. Open the reference from General Settings or Mod+/. Record, clear, or restore application bindings and keep local input operations in separate read-only groups. +Browse the commands available in the current window and find them by action, English alias, or key. Open the reference from General Settings or Mod+/. Record, clear, or restore application bindings; fixed input actions remain read-only. ## Table of Contents @@ -29,7 +29,9 @@ The Web app bundle mounts this package together with `shortcuts`. The reference `Mod+/` opens the reference when no modal is open or Settings is in front, and closes it when the reference is in front. While the reference is in front, the Settings command cannot open or close Settings. Held-key repeats are ignored. Recording, pending writes, and a nested confirmation prevent the reference shortcut from closing the dialog. -Search matches an ordered subsequence within one label, English alias, or key combination, ignoring case. Each matching command appears once. Rows within each group follow command ID order, independent of plugin registration order; search relevance takes precedence and equal matches retain that order. Application and fixed-action rows remain 42 CSS pixels high during normal display and recording; long command names are truncated. Application rows show command names and binding controls without availability subtitles or reason tooltips, including conflicting and invalid bindings. Commands that cannot execute remain silent. Fixed actions show disabled, dimmed key buttons without a separate status label; they cannot enter recording and do not highlight on hover. +Core actions follow a fixed product order, independent of plugin registration, unloading, or remounting. Stopping the current response ends the core list and remains read-only. Extension commands outside that order follow the core actions in stable command ID order; other fixed actions retain their groups. + +Search matches an ordered subsequence within one label, English alias, or key combination, ignoring case. Each matching command appears once. Search relevance takes precedence; equal matches retain the display order. Application and fixed-action rows remain 42 CSS pixels high during normal display and recording; long command names are truncated. Application rows show command names and binding controls without availability subtitles or reason tooltips, including conflicting and invalid bindings. Commands that cannot execute remain silent. Fixed actions show disabled, dimmed key buttons without a separate status label; they cannot enter recording and do not highlight on hover. Hover an application row or focus it with the keyboard to reveal its actions. The key badge highlights only while hovered; selecting it or Edit starts the same inline recorder. Unbound commands omit both remove controls. Windows and macOS Desktop record one or two overlapping non-modifier keys with optional modifiers; a third key rejects the draft. Releasing the first key saves the current combination, so sequential A then B records only A. Saving rejects combinations occupied by editable or fixed actions, including overlapping single-key and two-key bindings. The dialog close control exits recording. The recorder keeps the same height as key badges and uses a single border. Other environments retain Escape cancellation and Tab navigation. Saving and cancellation return focus to the dialog. macOS Web can record Option+Command+N reported as a dead key; composition and ordinary accent input remain protected. Remove clears the binding; Restore Default removes only that command’s override. System toasts announce successful writes and failures; a rejected combination marks the recorder with an error border. Release its non-modifier keys to record another combination without clicking; modifiers may remain held. Repeated identical errors leave a visible toast and its dismissal time unchanged; different errors and successful writes replace it immediately. An error can appear again after dismissal. Failed writes retain recorder focus and the draft for Retry Save or another recording. Configuration or command-catalog changes require review before a draft can be retried. Read failures disable editing and identify the active bindings and affected document in a system toast: Web uses the current origin’s localStorage entry `dsh.keybindings.v1`; Desktop uses `userData/keybindings.json`. Back up and repair damaged data before reloading the page or restarting Harness; upgrade Harness for a document written by a newer version. Restore All never overwrites unreadable data. The footer shows Restore All Defaults and the current runtime/platform’s override count, including removed bindings and commands that are not currently mounted. Search does not change the count. The action is disabled without overrides. Its confirmation initially focuses Cancel; cancellation returns focus to Restore All Defaults, including when opened from the recorder. Confirming restores only this profile. A stale revision closes the confirmation and requires another confirmation against the latest configuration; a failed write retains the accepted bindings and allows retry. diff --git a/packages/client/ui-shortcuts/README.zh.md b/packages/client/ui-shortcuts/README.zh.md index 77bcace81b..5b243a8b46 100644 --- a/packages/client/ui-shortcuts/README.zh.md +++ b/packages/client/ui-shortcuts/README.zh.md @@ -9,7 +9,7 @@ kind: "package-reference" ## 概述 -查看当前窗口可用的命令,按操作名称、英文别名或键位搜索。从通用设置或 Mod+/ 打开速查。录制、清除或恢复应用快捷键;局部输入操作在单独的只读分组中展示。 +查看当前窗口可用的命令,按操作名称、英文别名或键位搜索。从通用设置或 Mod+/ 打开速查。录制、清除或恢复应用快捷键;固定输入操作保持只读。 ## 目录 @@ -29,7 +29,9 @@ Web 应用 bundle 将此包与 `shortcuts` 一同挂载。速查仅展示已注 没有模态弹窗或设置位于最前方时,`Mod+/` 打开速查;速查位于最前方时,该快捷键关闭速查。速查位于前方时,设置命令不能打开或关闭设置。长按产生的重复按键不执行操作。录键期间、写入尚未完成或嵌套确认框打开时,速查快捷键不会关闭弹窗。 -搜索在单个操作名称、英文别名或按键组合内按字符顺序模糊匹配,忽略大小写。每个命中命令只出现一次。各分组内按命令 ID 排序,不受插件注册顺序影响;搜索时优先按相关性排序,同分项保留该顺序。正常显示和录制时,应用操作行和固定操作行均保持 42 CSS 像素高;过长的命令名称会被截断。应用命令行只显示名称和改键控件,不显示可用性副标题或原因悬浮提示,冲突和无效绑定也不例外。无法执行的命令静默结束。固定操作使用灰色禁用的键位按钮,不额外显示状态文字;按钮不能进入录键,悬停时不高亮。 +核心操作采用固定产品顺序,不受插件注册、卸载或重新挂载影响。停止当前回复位于核心列表末尾,仍为只读项。未列入该顺序的扩展命令在核心操作之后按命令 ID 稳定排列;其余固定操作保留原有分组。 + +搜索在单个操作名称、英文别名或按键组合内按字符顺序模糊匹配,忽略大小写。每个命中命令只出现一次。搜索时优先按相关性排序,同分项保留展示顺序。正常显示和录制时,应用操作行和固定操作行均保持 42 CSS 像素高;过长的命令名称会被截断。应用命令行只显示名称和改键控件,不显示可用性副标题或原因悬浮提示,冲突和无效绑定也不例外。无法执行的命令静默结束。固定操作使用灰色禁用的键位按钮,不额外显示状态文字;按钮不能进入录键,悬停时不高亮。 悬停应用操作行或通过键盘聚焦可显示操作图标。键位按钮仅在自身悬停时加深底色;点击它或编辑图标均进入同一行内录键。未绑定的命令不显示删除图标和“移除”文字按钮。Windows 和 macOS Desktop 可录制一至两个按住时间重叠的非修饰键,可搭配修饰键;第三个键会使草稿被拒绝。释放第一个键即保存当前组合,因此先后按 A、B 只录入 A。保存会拒绝被可编辑或固定操作占用的组合,包括相互重叠的单键与双键绑定。弹窗关闭控件可退出录制。录制框与键位标签保持相同高度,边框为单层。其他环境保留 Escape 取消和 Tab 导航。保存及取消后焦点返回弹窗。macOS Web 可录制被报告为 dead key 的 Option+Command+N;输入法组合和普通重音输入仍受保护。移除清空绑定,恢复默认只删除该命令的覆盖。系统提示反馈保存成功和失败;组合被拒绝时,录键框显示错误边框。松开非修饰键后即可直接录入新组合,无需再次点击,修饰键可继续按住。同一错误重复发生时沿用仍在显示的提示及其消失时间;不同错误和保存成功立即替换提示。提示消失后,同类错误可再次显示。写入失败保留录键框焦点和草稿,可重试保存或直接录入新组合。配置或命令目录变化后,需要核对最新配置才能重试草稿。读取失败时禁用编辑,并通过系统提示说明当前使用的键位及受影响的配置位置:Web 使用当前来源的 localStorage 项 `dsh.keybindings.v1`;Desktop 使用 `userData/keybindings.json`。内容损坏时先备份并修复配置,再刷新页面或重新启动 Harness;配置由更新版本写入时应升级 Harness。“恢复全部默认”不会覆盖无法读取的数据。底部显示“恢复全部默认”和当前运行环境及平台的自定义项数,包括已移除的绑定和当前未挂载的命令。搜索不影响计数。没有自定义项时,该操作禁用。确认框默认聚焦“取消”;取消后焦点返回“恢复全部默认”,从录制框打开确认时也如此。确认后仅恢复当前配置分组。配置版本过期时关闭确认框,需要针对最新配置重新确认;写入失败保留已接受的绑定,允许重试。 diff --git a/packages/client/ui-shortcuts/src/client/Reference.tsx b/packages/client/ui-shortcuts/src/client/Reference.tsx index 30b1f3a529..10ff58ccdb 100644 --- a/packages/client/ui-shortcuts/src/client/Reference.tsx +++ b/packages/client/ui-shortcuts/src/client/Reference.tsx @@ -22,6 +22,29 @@ export interface ReferenceInjected { type Store = PropsStore> type Locale = PropsLocale<'shortcuts'> +/** Core reference positions are independent of labels and plugin registration order. */ +const coreActionOrder = new Map([ + 'shortcuts.open', + 'session.new', + 'sidebar.left.toggle', + 'session.search', + 'workspace.add', + 'session.rename', + 'session.fork', + 'session.archive', + 'settings.open', + 'workspace.openLocal', + 'sidebar.right.toggle', + 'workspace.files', + 'browser.new', + 'terminal.new', + 'pane.split', + 'pane.fullscreen.toggle', + 'page.refresh', + 'page.close', + 'response.stop', +].map((id, index) => [id, index])) + /** * Render the General Settings action that opens the shortcut reference. * @param props - shared dialog action and localized labels. @@ -42,7 +65,7 @@ export function ShortcutsRow({ actions, t, useCatalog }: PropsRuntime<'settings. } /** - * Render commands and fixed actions in stable ID order within each group. Search relevance takes precedence. + * Render core actions in product order, then other commands by ID within each group. Search relevance takes precedence. * @param props - root store, effective catalog, and localized copy. * @returns the single reference dialog when open. */ @@ -120,7 +143,8 @@ export function ShortcutReference({ group: 'application' as const, })), ...fixedCatalog.map(row => ({ ...row, names: [row.id, row.keys.join(' ')] })), - ].sort((left, right) => Number(left.id > right.id) - Number(left.id < right.id)) + ].sort((left, right) => (coreActionOrder.get(left.id) ?? coreActionOrder.size) - (coreActionOrder.get(right.id) ?? coreActionOrder.size) + || Number(left.id > right.id) - Number(left.id < right.id)) const ranked = rankByName(entries.flatMap(row => row.names.map(name => ({ name, label: row.label, row }))), query.trim()) const matches = [...new Set(ranked.map(match => match.row))] const modifiedCount = Object.keys(config.document.profiles[`${runtime}:${platform}`] ?? {}).length diff --git a/packages/client/ui-shortcuts/tests/commands.client.spec.ts b/packages/client/ui-shortcuts/tests/commands.client.spec.ts index 9415229ba3..a58aa1ac3d 100644 --- a/packages/client/ui-shortcuts/tests/commands.client.spec.ts +++ b/packages/client/ui-shortcuts/tests/commands.client.spec.ts @@ -36,14 +36,16 @@ describe('assembled shortcut command owners', () => { const ownedRows = () => shortcuts.catalog.getSnapshot().filter(row => ownerIds.includes(row.id)) expect(ownedRows().map(row => row.id).sort()).toEqual(ownerIds) expect(ownedRows().filter(row => row.keys.length > 0).map(row => row.id)).toEqual(['shortcuts.open']) - const composerIds = ['fixed.send', 'fixed.newline', 'fixed.complementary', 'fixed.slash', 'fixed.mention'] + const conversationIds = ['fixed.send', 'fixed.newline', 'fixed.complementary', 'fixed.slash', 'fixed.mention', 'response.stop'] const fixedIds = () => shortcuts.fixedCatalog.getSnapshot().map(row => row.id) - expect(fixedIds()).toEqual(expect.arrayContaining(composerIds)) + expect(fixedIds()).toEqual(expect.arrayContaining(conversationIds)) + expect(shortcuts.fixedCatalog.getSnapshot().find(row => row.id === 'response.stop')) + .toMatchObject({ group: 'application', keys: ['Esc', 'Esc'] }) await client.unload('@deepseek-ai/dsh-client-ui-shortcuts') - expect(fixedIds()).toEqual(expect.arrayContaining(composerIds)) + expect(fixedIds()).toEqual(expect.arrayContaining(conversationIds)) expect(fixedIds()).not.toContain('fixed.move') await client.unload('@deepseek-ai/dsh-client-ui-conversation') - for (const id of composerIds) expect(fixedIds()).not.toContain(id) + for (const id of conversationIds) expect(fixedIds()).not.toContain(id) for (const owner of ['ui-settings-general', 'ui-layout']) await client.unload(`@deepseek-ai/dsh-client-${owner}`) expect(ownedRows()).toEqual([]) expect(shortcuts.fixedCatalog.getSnapshot().some(row => row.id.startsWith('fixed.'))).toBe(false) diff --git a/packages/client/ui-shortcuts/tests/reference.client.spec.tsx b/packages/client/ui-shortcuts/tests/reference.client.spec.tsx index 95a45c39bc..c3b37ef23f 100644 --- a/packages/client/ui-shortcuts/tests/reference.client.spec.tsx +++ b/packages/client/ui-shortcuts/tests/reference.client.spec.tsx @@ -168,32 +168,78 @@ function referenceFixture({ runtime = 'web', dictionary = en }: { runtime?: 'web return { store, catalog, fixedCatalog, config, edit, view } } -it('keeps row and tied-search order stable across registration and remount order', () => { +it('keeps core actions in product order across registration, remount and label changes', () => { const { catalog, fixedCatalog, store } = referenceFixture() const template = catalog.getSnapshot()[0]! - const first = { ...template, id: 'first.command' as ShortcutCommandId, label: 'Zulu', aliases: ['action'] } - const last = { ...template, id: 'last.command' as ShortcutCommandId, label: 'Alpha', aliases: ['action'] } - const fixedFirst: ShortcutFixedCatalogEntry = { id: 'fixed.first' as ShortcutCommandId, label: 'Zulu input', - keys: ['Enter'], bindings: [{ code: 'Enter', modifiers: [] }], group: 'input' } - const fixedLast = { ...fixedFirst, id: 'fixed.last' as ShortcutCommandId, label: 'Alpha input' } - const applicationRows = () => screen.getAllByRole('button', { name: /^Edit shortcut for/ }) - .map(button => button.getAttribute('aria-label')) - const inputRows = () => within(screen.getByRole('region', { name: en.input })).getAllByRole('listitem') - .map(row => row.textContent) + const core = [ + ['shortcuts.open', 'Keyboard shortcuts'], ['session.new', 'New session'], + ['sidebar.left.toggle', 'Toggle left sidebar'], ['session.search', 'Search sessions'], + ['workspace.add', 'Add workspace'], ['session.rename', 'Rename session'], + ['session.fork', 'Fork session'], ['session.archive', 'Archive session'], + ['settings.open', 'Open settings'], ['workspace.openLocal', 'Open workspace locally'], + ['sidebar.right.toggle', 'Toggle right sidebar'], ['workspace.files', 'Workspace files'], + ['browser.new', 'Browser'], ['terminal.new', 'New terminal'], ['pane.split', 'Split pane'], + ['pane.fullscreen.toggle', 'Toggle fullscreen'], ['page.refresh', 'Refresh page'], ['page.close', 'Close page'], + ] as const + const commands = core.map(([id, label]) => ({ ...template, id: id as ShortcutCommandId, label })) + const extensions = ([['extension.alpha', 'Zulu extension'], ['extension.zulu', 'Alpha extension']] as const).map(([id, label]) => ({ + ...template, id: id as ShortcutCommandId, label, + })) + const stop: ShortcutFixedCatalogEntry = { id: 'response.stop' as ShortcutCommandId, label: 'Stop reply', + keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'application' } + const fixed: ShortcutFixedCatalogEntry[] = [ + { ...stop, id: 'fixed.send' as ShortcutCommandId, label: 'Send', keys: ['Enter'], bindings: [{ code: 'Enter', modifiers: [] }], group: 'input' }, + { ...stop, id: 'fixed.newline' as ShortcutCommandId, label: 'Newline', keys: ['Shift', 'Enter'], bindings: [{ code: 'Enter', modifiers: ['shift'] }], group: 'input' }, + { ...stop, id: 'fixed.select' as ShortcutCommandId, label: 'Select', keys: ['Enter'], bindings: [{ code: 'Enter', modifiers: [] }], group: 'menus' }, + { ...stop, id: 'fixed.dismiss' as ShortcutCommandId, label: 'Dismiss', group: 'menus' }, + { ...stop, id: 'approval.accept' as ShortcutCommandId, label: 'Approve', keys: ['Enter'], bindings: [{ code: 'Enter', modifiers: [] }], group: 'approval' }, + stop, + ] + const labels = (group: string) => within(screen.getByRole('region', { name: group })).getAllByRole('listitem') + .map(row => row.firstElementChild?.textContent) + const expected = [...core.map(([, label]) => label), 'Stop reply', 'Zulu extension', 'Alpha extension'] for (const reversed of [true, false]) { act(() => { - catalog.set(reversed ? [last, first] : [first, last]) - fixedCatalog.set(reversed ? [fixedLast, fixedFirst] : [fixedFirst, fixedLast]) + catalog.set(reversed ? [...extensions, ...commands].reverse() : [...extensions, ...commands]) + fixedCatalog.set(reversed ? [...fixed].reverse() : fixed) }) - expect(applicationRows()).toEqual(['Edit shortcut for Zulu', 'Edit shortcut for Alpha']) - expect(inputRows()).toEqual(['Zulu inputEnter', 'Alpha inputEnter']) + expect(labels(en.application)).toEqual(expected) + expect(labels(en.input)).toEqual(['Newline', 'Send']) + expect(labels(en.menus)).toEqual(['Dismiss', 'Select']) + expect(labels(en.approval)).toEqual(['Approve']) } - act(() => { catalog.set([last]); fixedCatalog.set([fixedLast]) }) - act(() => { catalog.set([last, first]); fixedCatalog.set([fixedLast, fixedFirst]) }) - expect(applicationRows()).toEqual(['Edit shortcut for Zulu', 'Edit shortcut for Alpha']) - expect(inputRows()).toEqual(['Zulu inputEnter', 'Alpha inputEnter']) - act(() => { store.actions.search('action') }) - expect(applicationRows()).toEqual(['Edit shortcut for Zulu', 'Edit shortcut for Alpha']) + const stopButton = within(screen.getByRole('region', { name: en.application })).getByRole('button', { name: 'Stop reply Esc Esc' }) + expect(stopButton.hasAttribute('disabled')).toBe(true) + fireEvent.click(stopButton) + expect(screen.queryByRole('button', { name: 'Edit shortcut for Stop reply' })).toBeNull() + expect(screen.queryByRole('group', { name: 'Stop reply' })).toBeNull() + act(() => { catalog.set(extensions); fixedCatalog.set(fixed.filter(row => row.id !== stop.id)) }) + expect(labels(en.application)).toEqual(['Zulu extension', 'Alpha extension']) + act(() => { catalog.set([...extensions, ...[...commands].reverse()]); fixedCatalog.set(fixed) }) + expect(labels(en.application)).toEqual(expected) + act(() => { + catalog.set([...commands, ...extensions].map(row => ({ ...row, label: `操作:${row.label}` }))) + fixedCatalog.set(fixed.map(row => ({ ...row, label: `操作:${row.label}` }))) + store.actions.search('操作') + }) + expect(labels(en.application)).toEqual(expected.map(label => `操作:${label}`)) + expect(labels(en.input)).toEqual(['操作:Newline', '操作:Send']) +}) + +it('keeps product order for tied searches while prioritizing stronger matches', () => { + const { catalog, store } = referenceFixture() + const template = catalog.getSnapshot()[0]! + const first = { ...template, id: 'shortcuts.open' as ShortcutCommandId, label: 'Zulu', aliases: ['action', 's-e-a-r-c-h'] } + const second = { ...template, id: 'session.new' as ShortcutCommandId, label: 'Alpha', aliases: ['action', 's-e-a-r-c-h'] } + const extension = { ...template, id: 'extension.alpha' as ShortcutCommandId, label: 'Extension', aliases: ['action', 'search'] } + const labels = () => screen.getAllByRole('button', { name: /^Edit shortcut for/ }) + .map(button => button.getAttribute('aria-label')?.replace('Edit shortcut for ', '')) + act(() => { catalog.set([extension, second, first]); store.actions.search('action') }) + expect(labels()).toEqual(['Zulu', 'Alpha', 'Extension']) + act(() => { store.actions.search('search') }) + expect(labels()).toEqual(['Extension', 'Zulu', 'Alpha']) + act(() => { store.actions.search('') }) + expect(labels()).toEqual(['Zulu', 'Alpha', 'Extension']) }) it.each((['web', 'desktop'] as const).flatMap(runtime => (['invalid', 'future'] as const) @@ -218,7 +264,7 @@ it.each((['web', 'desktop'] as const).flatMap(runtime => (['invalid', 'future'] it('shows mounted fixed actions as searchable read-only rows and follows their label and lifetime', () => { const { fixedCatalog, store } = referenceFixture() const send = { id: 'fixed.send' as ShortcutCommandId, label: 'Send from catalog', keys: ['Enter'], bindings: [{ code: 'Enter', modifiers: [] }], group: 'input' as const } - const stop = { id: 'response.stop' as ShortcutCommandId, label: 'Stop reply', keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'input' as const } + const stop = { id: 'response.stop' as ShortcutCommandId, label: 'Stop reply', keys: ['Esc', 'Esc'], bindings: [{ code: 'Escape', modifiers: [] }], group: 'application' as const } const approve = { id: 'approval.accept' as ShortcutCommandId, label: 'Approve', keys: ['Enter'], bindings: [{ code: 'Enter', modifiers: [] }], group: 'approval' as const } expect(screen.queryByText(send.label)).toBeNull() act(() => { fixedCatalog.set([send, stop, approve]) })