Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(desktop): 导航栏「编辑」菜单、快捷键提示与官方快捷键弹层

hairyf0a0038f1be9c
diff --git a/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts b/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts
index 973f1174..42cded71 100644
--- a/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts
+++ b/packages/dsh-tauri-ui/src/client/styles/global.cssr.ts
@@ -9,10 +9,6 @@ export default c([
c('[class$="guide"]', {
gap: '8px',
}),
- c('[class$="entry"]:has(> button)', {
- padding: '0',
- gap: 0,
- }),
c('[class$="entry"]', {
border: 'none',
padding: '8px 16px',
@@ -99,4 +95,15 @@ export default c([
background: 'var(--dsw-alias-label-primary)',
}),
]),
+
+ c('[class$="sidebarCol"]', {
+ borderRight: 'none !important',
+ }),
+ c('[data-dsh-center-col]', {
+ borderRadius: '16px 0 0 0',
+ cornerShape: 'round',
+ }),
+ c('[data-slot="root"] > div', {
+ background: 'var(--dsw-specific-sidebar-fill)',
+ }),
])
diff --git a/packages/dsh-tauri-worktree/src/client/components/surface.tsx b/packages/dsh-tauri-worktree/src/client/components/surface.tsx
index 73c5ea70..96671b93 100644
--- a/packages/dsh-tauri-worktree/src/client/components/surface.tsx
+++ b/packages/dsh-tauri-worktree/src/client/components/surface.tsx
@@ -80,7 +80,7 @@ export function WorktreeSurface({ sessionId }: SurfaceBarProps): ReactElement |
</GoalBarAction>
)}
</GoalBar>
- <Logs log={state.log} open={logOpen} />
+ {logOpen && <Logs log={state.log} open={logOpen} />}
</div>
</div>
)
diff --git a/packages/dsh-tauri/src/client/apply.test.ts b/packages/dsh-tauri/src/client/apply.test.ts
index 97269170..0eb7fae0 100644
--- a/packages/dsh-tauri/src/client/apply.test.ts
+++ b/packages/dsh-tauri/src/client/apply.test.ts
@@ -17,6 +17,7 @@ const EXPECTED_LABELS = [
'dsh-tauri: zoom shortcuts (ctrl/cmd +/-/0)',
'dsh-tauri: sidebar tweaks (hide collapse toggle, center brand)',
'dsh-tauri: account sign-in (auto-open the authorize url)',
+ 'dsh-tauri: shortcuts (catalog report + edit commands)',
]
/** 假 MutationObserver:只保证 controller.observe 可用。 */
@@ -89,7 +90,7 @@ const disposers: (() => void)[] = []
/** 最小客户端 ctx:effect 按 cordis 的 `callback.call(fiber)` 语义绑定 this。 */
function fakeCtx(labels: string[]): ClientContext {
- return {
+ const ctx = {
effect(callback: (this: unknown) => () => void, label?: string) {
if (label !== undefined)
labels.push(label)
@@ -98,7 +99,12 @@ function fakeCtx(labels: string[]): ClientContext {
return dispose
},
layout: { toggleSidebar: () => {} },
- } as unknown as ClientContext
+ // 可选服务读取(`ctx.get`)与属性同源:老核心没有 `shortcuts`,属性面也不存在。
+ get(name: string): unknown {
+ return Reflect.get(ctx, name)
+ },
+ }
+ return ctx as unknown as ClientContext
}
beforeEach(() => {
@@ -142,7 +148,7 @@ describe('apply', () => {
expect(vi.getTimerCount()).toBe(0)
})
- it('内嵌页面保留四条 effect 与侧边栏、导航、缩放桥', async () => {
+ it('内嵌页面保留五条 effect 与侧边栏、导航、缩放桥', async () => {
const env = stubEnv()
const toggleSidebar = vi.fn()
diff --git a/packages/dsh-tauri/src/client/apply.ts b/packages/dsh-tauri/src/client/apply.ts
index 4cd2fb89..68aeca16 100644
--- a/packages/dsh-tauri/src/client/apply.ts
+++ b/packages/dsh-tauri/src/client/apply.ts
@@ -13,6 +13,7 @@
import type { ClientContext } from './types'
import { accountSignInFeature } from './register/account'
import { navigationFeature } from './register/navigation'
+import { shortcutsFeature } from './register/shortcuts'
import { sidebarFeature } from './register/sidebar'
import { sidebarTweaksFeature } from './register/sidebar-tweaks'
import { registerStyle } from './register/style'
@@ -25,6 +26,7 @@ const ZOOM_SHORTCUT_EFFECT = 'dsh-tauri: zoom shortcuts (ctrl/cmd +/-/0)'
const SIDEBAR_TWEAKS_EFFECT = 'dsh-tauri: sidebar tweaks (hide collapse toggle, center brand)'
const STYLE_EFFECT = 'dsh-tauri: style (sidebar background)'
const ACCOUNT_SIGN_IN_EFFECT = 'dsh-tauri: account sign-in (auto-open the authorize url)'
+const SHORTCUTS_EFFECT = 'dsh-tauri: shortcuts (catalog report + edit commands)'
/** 插件体:注册侧边栏桥、导航命令、缩放快捷键、账号登录接管与侧边栏 UI 微调。 */
export function apply(ctx: ClientContext): void {
// issue #573:独立浏览器没有桌面宿主,保留原生侧栏控件与缩放快捷键。
@@ -37,4 +39,5 @@ export function apply(ctx: ClientContext): void {
ctx.effect(zoomShortcutFeature, ZOOM_SHORTCUT_EFFECT)
ctx.effect(sidebarTweaksFeature, SIDEBAR_TWEAKS_EFFECT)
ctx.effect(accountSignInFeature, ACCOUNT_SIGN_IN_EFFECT)
+ ctx.effect(shortcutsFeature, SHORTCUTS_EFFECT)
}
diff --git a/packages/dsh-tauri/src/client/register/shortcuts.test.ts b/packages/dsh-tauri/src/client/register/shortcuts.test.ts
new file mode 100644
index 00000000..6d488e3c
--- /dev/null
+++ b/packages/dsh-tauri/src/client/register/shortcuts.test.ts
@@ -0,0 +1,168 @@
+/**
+ * register/shortcuts.test.ts — 快捷键桥的三条契约。
+ *
+ * 1. iframe → 宿主:核心 `ctx.shortcuts.catalog` 的目录投影后经 `dsh://shortcuts` 回报
+ * (壳层菜单右侧的按键提示都读它),配置变更后重发;
+ * 2. 宿主 → iframe:`dsh://edit` 在文档上执行对应编辑命令,非法 action 不进文档;
+ * 3. 宿主 → iframe:`dsh://shortcuts:open` 按官方 `shortcuts.open` 的**生效**绑定补一次
+ * 合成 keydown,弹出官方弹层与官方蒙版(壳层不自建对话框)。
+ *
+ * 核心没有 `shortcuts` 服务(老核心)时全部保持沉默,不得抛错。
+ */
+import type { ClientContext, ParentMessage } from '../types'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { CMD_EDIT, CMD_SHORTCUTS_OPEN, EVENT_SHORTCUTS, shortcutsFeature } from './shortcuts'
+
+const dispatchers = new Set<(event: KeyboardEvent) => void>()
+
+interface Harness {
+ sent: ParentMessage[]
+ dispatch: (data: unknown) => void
+ listeners: () => number
+ keydowns: KeyboardEvent[]
+}
+
+function stubEnv(): Harness {
+ const sent: ParentMessage[] = []
+ const listeners = new Set<(event: MessageEvent) => void>()
+ dispatchers.clear()
+ const parent = { postMessage: (data: ParentMessage) => void sent.push(data) }
+ vi.stubGlobal('window', {
+ parent,
+ addEventListener: (type: string, handler: (event: never) => void) => {
+ if (type === 'message')
+ listeners.add(handler as (event: MessageEvent) => void)
+ if (type === 'keydown')
+ dispatchers.add(handler as (event: KeyboardEvent) => void)
+ },
+ removeEventListener: (_type: string, handler: (event: never) => void) => {
+ listeners.delete(handler as (event: MessageEvent) => void)
+ dispatchers.delete(handler as (event: KeyboardEvent) => void)
+ },
+ dispatchEvent: (event: KeyboardEvent) => {
+ for (const handler of dispatchers)
+ handler(event)
+ return true
+ },
+ })
+ vi.stubGlobal('document', { execCommand: vi.fn(() => true) })
+ return {
+ sent,
+ listeners: () => listeners.size,
+ keydowns: [],
+ dispatch(data: unknown) {
+ for (const handler of listeners)
+ handler({ source: parent, data } as unknown as MessageEvent)
+ },
+ }
+}
+
+const disposers: (() => void)[] = []
+
+function fakeCtx(service: unknown): ClientContext {
+ return {
+ get: () => service,
+ effect(callback: (this: unknown) => () => void) {
+ const dispose = callback.call({ ctx: this })
+ disposers.push(dispose)
+ return dispose
+ },
+ } as unknown as ClientContext
+}
+
+function catalogService(rows: unknown[], subscribe?: (listener: () => void) => () => void) {
+ return { catalog: { getSnapshot: () => rows, ...subscribe === undefined ? {} : { subscribe } } }
+}
+
+afterEach(() => {
+ for (const dispose of disposers.splice(0))
+ dispose()
+ vi.unstubAllGlobals()
+})
+
+describe('shortcutsFeature', () => {
+ it('projects the catalog to the shell and republishes on change', () => {
+ const env = stubEnv()
+ let notify = (): void => {}
+ const ctx = fakeCtx(catalogService([
+ { id: 'session.new', label: 'New chat', keys: ['Ctrl+N'], aria: 'Control+N', modified: false },
+ { id: 'workspace.add', label: 'Open folder', keys: ['Ctrl+O'] },
+ { id: 42, label: 'broken' },
+ { id: 'no.label' },
+ ], (listener) => {
+ notify = listener
+ return () => {}
+ }))
+
+ shortcutsFeature.call(ctx)
+
+ expect(env.sent).toEqual([{
+ type: EVENT_SHORTCUTS,
+ rows: [
+ { id: 'session.new', label: 'New chat', keys: ['Ctrl+N'], aria: 'Control+N' },
+ { id: 'workspace.add', label: 'Open folder', keys: ['Ctrl+O'] },
+ ],
+ }])
+ expect(env.listeners()).toBe(1)
+
+ notify()
+ expect(env.sent).toHaveLength(2)
+ })
+
+ it('stays inert when the core has no shortcuts service', () => {
+ const env = stubEnv()
+
+ expect(() => shortcutsFeature.call(fakeCtx(undefined))).not.toThrow()
+ expect(env.sent).toEqual([])
+ expect(env.listeners()).toBe(0)
+ })
+
+ it('runs the edit command and ignores unknown actions', () => {
+ const env = stubEnv()
+ const exec = vi.fn(() => true)
+ vi.stubGlobal('document', { execCommand: exec })
+
+ shortcutsFeature.call(fakeCtx(catalogService([])))
+ env.dispatch({ type: CMD_EDIT, action: 'copy' })
+ env.dispatch({ type: CMD_EDIT, action: 'rm -rf' })
+ env.dispatch({ type: 'dsh://sidebar:toggle' })
+
+ expect(exec).toHaveBeenCalledTimes(1)
+ expect(exec).toHaveBeenCalledWith('copy')
+ })
+
+ /** 官方弹层:用目录里的生效绑定合成 keydown(官方适配器只看 code + 修饰键)。 */
+ it('opens the official reference with the effective binding', () => {
+ const env = stubEnv()
+ class FakeKeyboardEvent {
+ code: string
+ ctrlKey: boolean
+ metaKey: boolean
+ altKey: boolean
+ shiftKey: boolean
+ constructor(_type: string, init: KeyboardEventInit = {}) {
+ this.code = init.code ?? ''
+ this.ctrlKey = Boolean(init.ctrlKey)
+ this.metaKey = Boolean(init.metaKey)
+ this.altKey = Boolean(init.altKey)
+ this.shiftKey = Boolean(init.shiftKey)
+ }
+ }
+ vi.stubGlobal('KeyboardEvent', FakeKeyboardEvent)
+ let seen: FakeKeyboardEvent | undefined
+ const handler = (event: FakeKeyboardEvent): void => {
+ seen = event
+ }
+ dispatchers.add(handler as unknown as (event: KeyboardEvent) => void)
+
+ shortcutsFeature.call(fakeCtx(catalogService([
+ { id: 'shortcuts.open', label: 'Shortcuts', keys: ['Ctrl+/'], binding: { code: 'Slash', modifiers: ['control'] } },
+ ])))
+ env.dispatch({ type: CMD_SHORTCUTS_OPEN })
+
+ expect(seen?.code).toBe('Slash')
+ expect(seen?.ctrlKey).toBe(true)
+ expect(seen?.metaKey).toBe(false)
+ dispatchers.delete(handler as unknown as (event: KeyboardEvent) => void)
+ })
+})
diff --git a/packages/dsh-tauri/src/client/register/shortcuts.ts b/packages/dsh-tauri/src/client/register/shortcuts.ts
new file mode 100644
index 00000000..e8ee3e58
--- /dev/null
+++ b/packages/dsh-tauri/src/client/register/shortcuts.ts
@@ -0,0 +1,155 @@
+/**
+ * register/shortcuts.ts — 快捷键目录桥(iframe ↔ 宿主导航栏)。
+ *
+ * iframe → 宿主:把核心 `ctx.shortcuts` 的目录投影成 `{ id, label, keys, aria }`,经
+ * `dsh://shortcuts` 送达壳层;壳层的「文件」「帮助」菜单右侧按键提示与「显示键盘快捷键」
+ * 清单都读这一份(配置变更后重发,用户改键即时生效)。
+ *
+ * 宿主 → iframe:`dsh://edit` 由壳层的「编辑」菜单发出,在文档上执行对应编辑命令;
+ * 剪贴板仍走系统快捷键(WebView 的原生粘贴不对脚本开放)。
+ *
+ * 协议字面量与宿主侧 `src/layout/components/webview.tsx` / `navbar.tsx` 逐字一致。
+ */
+import type { ParentMessage } from '../types'
+import { invokeParent } from '../service/invoke-parent'
+import { listenParent } from '../service/listen-parent'
+import { defineRegister } from './index'
+
+/** iframe → 宿主:快捷键目录回报。 */
+export const EVENT_SHORTCUTS = 'dsh://shortcuts'
+
+/** 宿主 → iframe:编辑菜单命令。 */
+export const CMD_EDIT = 'dsh://edit'
+
+/** 宿主 → iframe:打开官方「键盘快捷键」弹层(官方 `shortcuts.open` 命令,含官方蒙版)。 */
+export const CMD_SHORTCUTS_OPEN = 'dsh://shortcuts:open'
+
+/** 菜单可执行的编辑动作(`document.execCommand` 的命令名)。 */
+export const EDIT_ACTIONS = ['undo', 'redo', 'cut', 'copy', 'paste', 'selectAll'] as const
+
+export type EditAction = typeof EDIT_ACTIONS[number]
+
+/** 上报给壳层的一行目录(官方 `ShortcutCatalogEntry` 的投影)。 */
+export interface ShortcutRowReport {
+ id: string
+ label: string
+ keys: readonly string[]
+ aria?: string
+}
+
+interface CatalogLike {
+ getSnapshot?: () => unknown
+ subscribe?: (listener: () => void) => () => void
+}
+
+interface ShortcutsLike {
+ catalog?: CatalogLike
+}
+
+const ROW_MAX = 200
+
+export const shortcutsFeature = defineRegister((controller, ctx) => {
+ const service = ctx.get('shortcuts') as ShortcutsLike | undefined
+ const catalog = service?.catalog
+ const snapshot = catalog?.getSnapshot
+ if (typeof snapshot !== 'function')
+ return
+
+ const report = (): void => {
+ invokeParent({ type: EVENT_SHORTCUTS, rows: project(snapshot.call(catalog)) })
+ }
+ report()
+ if (typeof catalog?.subscribe === 'function')
+ controller.add(catalog.subscribe(report))
+
+ controller.add(listenParent<ParentMessage>((data) => {
+ if (data.type === CMD_SHORTCUTS_OPEN) {
+ openReference(snapshot.call(catalog))
+ return
+ }
+ runEdit(data.action)
+ }, [CMD_EDIT, CMD_SHORTCUTS_OPEN]))
+})
+
+/** 目录投影:只保留有 id 与文案的行,`keys` 逐项取字符串。 */
+function project(rows: unknown): ShortcutRowReport[] {
+ if (!Array.isArray(rows))
+ return []
+ const out: ShortcutRowReport[] = []
+ for (const row of rows) {
+ if (typeof row !== 'object' || row === null)
+ continue
+ const entry = row as { id?: unknown, label?: unknown, keys?: unknown, aria?: unknown }
+ if (typeof entry.id !== 'string' || typeof entry.label !== 'string')
+ continue
+ const keys = Array.isArray(entry.keys) ? entry.keys.filter((key): key is string => typeof key === 'string') : []
+ out.push({
+ id: entry.id,
+ label: entry.label,
+ keys,
+ ...typeof entry.aria === 'string' ? { aria: entry.aria } : {},
+ })
+ if (out.length >= ROW_MAX)
+ break
+ }
+ return out
+}
+
+/** 编辑命令:文档级 `document.execCommand`;失败只告警(原生快捷键仍是主路径)。 */
+function runEdit(action: unknown): void {
+ if (typeof action !== 'string' || !EDIT_ACTIONS.includes(action as EditAction))
+ return
+ if (typeof document === 'undefined')
+ return
+ try {
+ document.execCommand(action)
+ }
+ catch (error) {
+ console.warn('[dsh-tauri] running the edit command failed:', error)
+ }
+}
+
+/**
+ * 打开官方「键盘快捷键」弹层:官方命令没有公开的调用口,按其**生效**绑定补一次合成
+ * keydown(官方键盘适配器只读 `event.code` 与修饰键,不校验 `isTrusted`),
+ * 走的仍是官方 `shortcuts.open` 命令与其 `shell.overlay` 弹层(含官方蒙版)。
+ */
+function openReference(rows: unknown): void {
+ if (typeof window === 'undefined' || typeof KeyboardEvent !== 'function')
+ return
+ const binding = bindingOf(rows, 'shortcuts.open')
+ const event = new KeyboardEvent('keydown', {
+ bubbles: true,
+ cancelable: true,
+ ...binding ?? { code: 'Slash', ctrlKey: true, metaKey: false, altKey: false, shiftKey: false },
+ })
+ window.dispatchEvent(event)
+}
+
+/** 目录里取某命令的生效绑定,翻成 KeyboardEvent 的物理键 + 修饰键字段。 */
+function bindingOf(rows: unknown, id: string): KeyboardEventInit | undefined {
+ if (!Array.isArray(rows))
+ return undefined
+ for (const row of rows) {
+ if (typeof row !== 'object' || row === null)
+ continue
+ const entry = row as { id?: unknown, binding?: unknown }
+ if (entry.id !== id)
+ continue
+ const binding = entry.binding
+ if (typeof binding !== 'object' || binding === null)
+ return undefined
+ const { code, modifiers } = binding as { code?: unknown, modifiers?: unknown }
+ if (typeof code !== 'string')
+ return undefined
+ const list = Array.isArray(modifiers) ? modifiers.filter((value): value is string => typeof value === 'string') : []
+ return {
+ code,
+ ctrlKey: list.some(value => value === 'control' || value === 'ctrl'),
+ metaKey: list.some(value => value === 'meta' || value === 'command' || value === 'cmd'),
+ altKey: list.some(value => value === 'alt' || value === 'option'),
+ shiftKey: list.includes('shift'),
+ }
+ }
+ return undefined
+}
diff --git a/src/hooks/use-dsh-shortcuts.ts b/src/hooks/use-dsh-shortcuts.ts
new file mode 100644
index 00000000..5ab96978
--- /dev/null
+++ b/src/hooks/use-dsh-shortcuts.ts
@@ -0,0 +1,23 @@
+import { createGlobalState } from '@reause/core'
+
+/** 核心回报的一行快捷键目录(`dsh-tauri` 的 `dsh://shortcuts` 投影)。 */
+export interface DshShortcutRow {
+ id: string
+ label: string
+ keys: readonly string[]
+ aria?: string
+}
+
+export const useDshShortcuts = createGlobalState<{ rows: readonly DshShortcutRow[] }>({ rows: [] })
+
+/**
+ * 菜单项右侧的按键提示:按命令 id 取键位文本,未注册(老核心 / 用户清空)即不显示。
+ *
+ * 只显示 dsh 应用真的会响应的绑定(`session.new`、`workspace.add`、`settings.open`…),
+ * 壳层自己没实现的动作不留假提示。
+ */
+export function shortcutHint(rows: readonly DshShortcutRow[], id: string): string | undefined {
+ const keys = rows.find(row => row.id === id)?.keys
+ const text = keys?.join(' ')
+ return text === undefined || text.length === 0 ? undefined : text
+}
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index dd84faab..0cbb3ac5 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -70,6 +70,14 @@
"menu.about": "About Desktop",
"menu.run_logs": "Run Logs",
"menu.file": "File",
+ "menu.edit": "Edit",
+ "menu.undo": "Undo",
+ "menu.redo": "Redo",
+ "menu.cut": "Cut",
+ "menu.copy": "Copy",
+ "menu.paste": "Paste",
+ "menu.select_all": "Select All",
+ "menu.keyboard_shortcuts": "Show Keyboard Shortcuts",
"menu.run": "Run",
"menu.new_window": "New Window",
"menu.new_chat": "New Chat",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index 284bfb94..501aff5c 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -70,6 +70,14 @@
"menu.about": "关于 Desktop",
"menu.run_logs": "运行日志",
"menu.file": "文件",
+ "menu.edit": "编辑",
+ "menu.undo": "撤销",
+ "menu.redo": "重做",
+ "menu.cut": "剪切",
+ "menu.copy": "复制",
+ "menu.paste": "粘贴",
+ "menu.select_all": "全选",
+ "menu.keyboard_shortcuts": "显示键盘快捷键",
"menu.run": "运行",
"menu.new_window": "新建窗口",
"menu.new_chat": "新聊天",
diff --git a/src/layout/components/navbar.tsx b/src/layout/components/navbar.tsx
index d610b576..5175b03d 100644
--- a/src/layout/components/navbar.tsx
+++ b/src/layout/components/navbar.tsx
@@ -20,6 +20,7 @@ import { If } from 'react-if-lite'
import { cn } from 'tailwind-variants'
import { useStore } from 'valtio-define'
import { queryKeys } from '@/config/query-keys'
+import { shortcutHint, useDshShortcuts } from '@/hooks/use-dsh-shortcuts'
import { useDshStyle } from '@/hooks/use-dsh-style'
import { useListen } from '@/hooks/use-listen'
import { store } from '@/store'
@@ -79,8 +80,20 @@ const DOCS_URL = 'https://dshtauri.mintlify.site'
/** 「文件」菜单的动作 id(宿主侧统一分发,避免菜单项内散落逻辑)。 */
type FileAction = 'new-window' | 'new-chat' | 'open-folder' | 'close' | 'quit'
+/**
+ * 「编辑」菜单项:`dsh://edit` 的 action 与平台加速键(macOS 用 ⌘,与官方桌面端一致)。
+ */
+const EDIT_ITEMS = [
+ { id: 'undo', labelKey: 'menu.undo', key: 'Z', shift: false },
+ { id: 'redo', labelKey: 'menu.redo', key: 'Z', shift: true },
+ { id: 'cut', labelKey: 'menu.cut', key: 'X', shift: false },
+ { id: 'copy', labelKey: 'menu.copy', key: 'C', shift: false },
+ { id: 'paste', labelKey: 'menu.paste', key: 'V', shift: false },
+ { id: 'selectAll', labelKey: 'menu.select_all', key: 'A', shift: false },
+] as const
+
/** 「帮助」菜单的动作 id。 */
-type HelpAction = 'copy-run-logs' | 'check-update' | 'about' | 'documentation'
+type HelpAction = 'keyboard-shortcuts' | 'copy-run-logs' | 'check-update' | 'about' | 'documentation'
/** 「运行」菜单项:直接打开配置对话框并定位到对应面板。 */
const CONFIG_TABS: { id: ConfigTab, labelKey: string }[] = [
@@ -193,8 +206,26 @@ function useMaximized() {
return isMaximized
}
-export interface NavbarProps {
- /** iframe 回报的 dsh 侧边栏折叠状态(导航桥逻辑在 `iframe.tsx`) */
+/** 菜单项:左侧文案 + 右侧按键提示;没有生效绑定时只渲染文案(布局不变)。 */
+function ShortcutLabel({ label, hint }: { label: string, hint?: string }) {
+ if (hint == null)
+ return <Label>{label}</Label>
+ return (
+ <span className="flex w-full items-center justify-between gap-6">
+ <Label>{label}</Label>
+ <span className="shrink-0 font-mono text-xs text-muted" data-testid="dsh-navbar-shortcut-hint">{hint.replaceAll(' ', '')}</span>
+ </span>
+ )
+}
+
+/** 编辑菜单的加速键文本:macOS 用 ⌘,其余平台用 Ctrl(与官方桌面端同一组)。 */
+function editAccelerator(key: string, shift: boolean): string {
+ if (IS_MACOS)
+ return `⌘${shift ? '⇧' : ''}${key}`
+ return `Ctrl+${shift ? 'Shift+' : ''}${key}`
+}
+
+export interface NavbarProps { /** iframe 回报的 dsh 侧边栏折叠状态(导航桥逻辑在 `iframe.tsx`) */
sidebarCollapsed?: boolean
/** 切换 iframe 内 dsh 侧边栏(向 iframe 发 `dsh://sidebar:toggle`);传入时启用左侧导航控制 */
onToggleSidebar?: () => void
@@ -202,9 +233,13 @@ export interface NavbarProps {
onNewChat?: () => void
/** 打开文件夹:向 iframe 发 `dsh://workspace:add`(dsh 官方「添加工作区」);传入时该项可用 */
onOpenFolder?: () => void
+ /** 编辑菜单动作:向 iframe 发 `dsh://edit`(dsh-tauri 的 `client/register/shortcuts.ts` 执行) */
+ onEditAction?: (action: string) => void
+ /** 显示键盘快捷键:向 iframe 发 `dsh://shortcuts:open`,弹官方 `shortcuts.open` 弹层(官方蒙版) */
+ onOpenShortcuts?: () => void
}
-export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder }: NavbarProps) {
+export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder, onEditAction, onOpenShortcuts }: NavbarProps) {
const { t } = useTranslation()
const isFullscreen = useMacOSFullscreen()
const isMaximized = useMaximized()
@@ -216,6 +251,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
})
const { updateInfo } = useStore(store.desktopUpdater)
const [dshStyle] = useDshStyle()
+ const [{ rows: shortcutRows }] = useDshShortcuts()
// 「运行」菜单受控开合:快捷重启按钮不是菜单项,走不到 React Aria 的
// 「项选中即收起」,收起得自己来,否则重启期间菜单会一直挂在新页面上。
const [runMenuOpen, setRunMenuOpen] = useState(false)
@@ -262,6 +298,8 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
void copyRunLogs()
else if (key === 'documentation')
void openDocumentation()
+ else if (key === 'keyboard-shortcuts')
+ onOpenShortcuts?.()
}
function handleFileAction(key: FileAction) {
@@ -399,7 +437,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
return (
<div
className={cn(
- 'relative flex h-11 w-full flex-none select-none items-center gap-0.5 border-b border-line bg-panel',
+ 'relative flex h-11 w-full flex-none select-none items-center gap-0.5 bg-panel',
{
'hidden': IS_MACOS && isFullscreen,
'pl-20 pr-1.5': IS_MACOS && !isFullscreen,
@@ -460,7 +498,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
textValue={t('menu.new_chat')}
onAction={() => handleFileAction('new-chat')}
>
- <Label>{t('menu.new_chat')}</Label>
+ <ShortcutLabel label={t('menu.new_chat')} hint={shortcutHint(shortcutRows, 'session.new')} />
</Dropdown.Item>
<Dropdown.Item
className="rounded-md"
@@ -470,7 +508,7 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
textValue={t('menu.open_folder')}
onAction={() => handleFileAction('open-folder')}
>
- <Label>{t('menu.open_folder')}</Label>
+ <ShortcutLabel label={t('menu.open_folder')} hint={shortcutHint(shortcutRows, 'workspace.add')} />
</Dropdown.Item>
<Dropdown.Item
className="rounded-md"
@@ -493,7 +531,40 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
</Dropdown.Menu>
</Dropdown.Popover>
</Dropdown>
+ {/* 「编辑」:与官方桌面端同一组编辑命令(撤销/重做/剪切/复制/粘贴/全选)。
+ 动作经 `dsh://edit` 交给 iframe 内的 dsh-tauri 插件在文档上执行,
+ 未安装插件(没有接收方)时整组禁用;加速键是系统/WebView 真实绑定,
+ 只作为提示(粘贴仍走原生快捷键,脚本无权读剪贴板)。 */}
+ <Dropdown>
+ <Button
+ className="rounded-lg h-6 text-[12.5px] px-1.5"
+ size="sm"
+ variant="ghost"
+ aria-label={t('menu.edit')}
+ data-testid="dsh-navbar-menu-edit"
+ >
+ {t('menu.edit')}
+ </Button>
+ <Dropdown.Popover className="rounded-md min-w-55" data-testid="dsh-navbar-menu-popover">
+ <Dropdown.Menu>
+ {EDIT_ITEMS.map(item => (
+ <Dropdown.Item
+ key={item.id}
+ className="rounded-md"
+ id={item.id}
+ data-testid={`dsh-navbar-item-edit-${item.id}`}
+ isDisabled={onEditAction == null}
+ textValue={t(item.labelKey)}
+ onAction={() => onEditAction?.(item.id)}
+ >
+ <ShortcutLabel label={t(item.labelKey)} hint={editAccelerator(item.key, item.shift)} />
+ </Dropdown.Item>
+ ))}
+ </Dropdown.Menu>
+ </Dropdown.Popover>
+ </Dropdown>
<Dropdown isOpen={runMenuOpen} onOpenChange={setRunMenuOpen}>
+ {' '}
<Button
className="rounded-lg h-6 text-[12.5px] px-1.5"
size="sm"
@@ -558,6 +629,15 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, o
</Button>
<Dropdown.Popover className="rounded-md min-w-55" data-testid="dsh-navbar-menu-popover">
<Dropdown.Menu>
+ <Dropdown.Item
+ className="rounded-md"
+ id="keyboard-shortcuts"
+ data-testid="dsh-navbar-item-keyboard-shortcuts"
+ textValue={t('menu.keyboard_shortcuts')}
+ onAction={() => onHelpAction('keyboard-shortcuts')}
+ >
+ <ShortcutLabel label={t('menu.keyboard_shortcuts')} hint={shortcutHint(shortcutRows, 'shortcuts.open')} />
+ </Dropdown.Item>
<Dropdown.Item
className="rounded-md"
id="copy-run-logs"
diff --git a/src/layout/components/webview.tsx b/src/layout/components/webview.tsx
index fe00284b..f695c166 100644
--- a/src/layout/components/webview.tsx
+++ b/src/layout/components/webview.tsx
@@ -1,6 +1,8 @@
+import type { DshShortcutRow } from '@/hooks/use-dsh-shortcuts'
import { useRef, useState } from 'react'
import { If } from 'react-if-lite'
import { useStore } from 'valtio-define'
+import { useDshShortcuts } from '@/hooks/use-dsh-shortcuts'
import { useDshStyle } from '@/hooks/use-dsh-style'
import { useIframeMessage } from '@/hooks/use-iframe-message'
import { useIframePost } from '@/hooks/use-iframe-post'
@@ -15,6 +17,7 @@ import { PreinstallSetup } from './setup-preinstall'
interface NavBridgeMessage {
type?: string
collapsed?: boolean
+ rows?: unknown
}
/**
@@ -33,6 +36,7 @@ export function Webview() {
const post = useIframePost(iframeRef)
const [dshStyle] = useDshStyle()
+ const [, setDshShortcuts] = useDshShortcuts()
const { status, serviceHealthy } = useStore(store.harness)
const { recovery } = useStore(store.recovery)
@@ -42,6 +46,9 @@ export function Webview() {
if (data.type === 'dsh://sidebar:collapsed') {
setSidebarCollapsed(Boolean(data.collapsed))
}
+ else if (data.type === 'dsh://shortcuts') {
+ setDshShortcuts({ rows: parseShortcutRows(data.rows) })
+ }
})
// 4. 根据当前状态决定中间区域渲染内容
@@ -72,6 +79,8 @@ export function Webview() {
onToggleSidebar: () => post({ type: 'dsh://sidebar:toggle' }),
onNewChat: () => post({ type: 'dsh://session:new' }),
onOpenFolder: () => post({ type: 'dsh://workspace:add' }),
+ onEditAction: (action: string) => post({ type: 'dsh://edit', action }),
+ onOpenShortcuts: () => post({ type: 'dsh://shortcuts:open' }),
}
: {}
@@ -85,3 +94,24 @@ export function Webview() {
</main>
)
}
+
+/** 目录行校验:只接受有 id 与文案的行,键位逐项取字符串(桥消息按不可信输入处理)。 */
+function parseShortcutRows(rows: unknown): DshShortcutRow[] {
+ if (!Array.isArray(rows))
+ return []
+ const out: DshShortcutRow[] = []
+ for (const row of rows) {
+ if (typeof row !== 'object' || row === null)
+ continue
+ const entry = row as { id?: unknown, label?: unknown, keys?: unknown, aria?: unknown }
+ if (typeof entry.id !== 'string' || typeof entry.label !== 'string')
+ continue
+ out.push({
+ id: entry.id,
+ label: entry.label,
+ keys: Array.isArray(entry.keys) ? entry.keys.filter((key): key is string => typeof key === 'string') : [],
+ ...typeof entry.aria === 'string' ? { aria: entry.aria } : {},
+ })
+ }
+ return out
+}