From 8096e18504d9f26fe0b5ade76398a3738e782f80 Mon Sep 17 00:00:00 2001 From: fz Date: Mon, 12 Oct 2026 23:34:02 +0800 Subject: [PATCH 1/4] feat(web): add desktop conversation font size shortcuts --- packages/client/ui-theme/README.i18n.yaml | 4 +- packages/client/ui-theme/README.md | 2 + packages/client/ui-theme/README.zh.md | 2 + packages/client/ui-theme/package.json | 2 + packages/client/ui-theme/src/client/index.ts | 30 +++- .../ui-theme/tests/apply.client.spec.ts | 140 +++++++++++++++++- packages/client/ui-theme/tsconfig.client.json | 3 + pnpm-lock.yaml | 3 + 8 files changed, 182 insertions(+), 4 deletions(-) diff --git a/packages/client/ui-theme/README.i18n.yaml b/packages/client/ui-theme/README.i18n.yaml index d828a43c5a..9544d10046 100644 --- a/packages/client/ui-theme/README.i18n.yaml +++ b/packages/client/ui-theme/README.i18n.yaml @@ -18,8 +18,8 @@ en: 5a279269e31713c1 zh: dcd5c31fbdfd63e2 /deepseek-ai-dsh-client-ui-theme/use-this-package/appearance-and-font-size: - en: ebf89ea31593f49c - zh: 06c98ba30ec3bb6b + en: b1355dc143f22d2f + zh: a288c70c1fc73704 /deepseek-ai-dsh-client-ui-theme/use-this-package/fonts: en: b45d5b48ca799c3a zh: af65514b3759204f diff --git a/packages/client/ui-theme/README.md b/packages/client/ui-theme/README.md index 1ed77be835..2103890cca 100644 --- a/packages/client/ui-theme/README.md +++ b/packages/client/ui-theme/README.md @@ -31,6 +31,8 @@ Users switch the color scheme, font sizes, and fonts from rows in Settings (Gene The plugin registers Appearance preference cubes and the text font-size stepper in the General section. A More font settings button after the stepper expands a region below it, collapsed on every settings open, with a font row for each of text, code, and the terminal, plus the code and terminal font-size steppers. The text stepper accepts integer values from 10 through 22 px and defaults to 14 px. It changes conversation headings and base text by the same increment, including the user bubble and composer draft; flow-row titles, summaries, and tables follow one step under the body size, while small text keeps a fixed size. The code stepper (10–16 px, default 11) sets the code-block size; inline code stays 1 px larger, and the small tool-output variant uses the same size. The terminal stepper (10–20 px, default 13) sets the sidebar terminal cell font size; changing it keeps the shell and output and refits the grid. Each accepted change writes through the Host settings API. Rapid changes serialize in gesture order with namespace revisions, and a rejected latest write reloads the durable values. +Desktop's fixed `Cmd`/`Ctrl` + `+` (or `=`) and `Cmd`/`Ctrl` + `-` shortcuts change the text size by 1 px through the same setting, within 10–22 px. They appear in the shortcut reference and work in the main page and its text inputs; terminal input retains its own key handling. Web retains the browser's zoom shortcuts. + ### Fonts Three rows set the text font (interface and conversation text), the code font (code blocks, inline code, and other `--ds-font-family-code` text), and the sidebar terminal font independently. Each field takes comma-separated family names and commits on blur or Enter; an empty field restores the built-in stack. The service normalizes each list by dropping quotes, backslashes, angle brackets, and control characters and double-quoting every name except CSS generic families, then stores it in `textFontFamily`, `codeFontFamily`, or `terminalFontFamily`. The user list precedes the role's built-in stack, so a font missing on the machine falls back to the default. The field accepts any installed font name; it does not enumerate local fonts. diff --git a/packages/client/ui-theme/README.zh.md b/packages/client/ui-theme/README.zh.md index bac4c7f3a3..81b5a09d89 100644 --- a/packages/client/ui-theme/README.zh.md +++ b/packages/client/ui-theme/README.zh.md @@ -31,6 +31,8 @@ kind: "package-reference" 插件在「通用」分区注册外观偏好方块与正文字号步进器。步进器后的「更多字体设置」按钮在其下方展开一个区域,每次打开设置时均为折叠状态,其中包含正文、代码与终端各自的字体行,以及代码与终端的字号步进器。正文步进器接受 10 至 22 px 的整数,默认值为 14 px。它以相同增量调整会话标题与基础文本,包括用户气泡与 composer 草稿;流内行的标题、摘要与表格跟随比正文低一档的字号,小号文本保持固定字号。代码步进器(10–16 px,默认 11)设置代码块字号;行内代码保持大 1 px,工具输出的小号变体使用相同字号。终端步进器(10–20 px,默认 13)设置侧栏终端的单元格字号;修改后保留 shell 与输出,并重新适配网格。每次通过的变更都经 Host settings API 写入。连续快速变更按操作顺序携带命名空间 revision 串行写入,最新写入被拒时重新加载持久值。 +Desktop 的固定快捷键 `Cmd`/`Ctrl` + `+`(或 `=`)和 `Cmd`/`Ctrl` + `-` 通过同一设置每次增减 1 px,范围为 10–22 px。它们显示在快捷键参考中,可在主页面及其文本输入框内使用;终端输入保留自身的按键处理。Web 保留浏览器的缩放快捷键。 + ### 字体 三行分别独立设置正文字体(界面与会话正文)、代码字体(代码块、行内代码及其他使用 `--ds-font-family-code` 的文本)与侧栏终端字体。每个输入框接受逗号分隔的字体名,失焦或按 Enter 时提交;清空输入框即恢复内置字体栈。服务会规范化每个列表:去掉引号、反斜杠、尖括号与控制字符,并给 CSS 通用字体族以外的名称加双引号,然后存入 `textFontFamily`、`codeFontFamily` 或 `terminalFontFamily`。用户列表排在该类内置字体栈之前,因此本机缺少的字体会回退到默认字体。输入框接受任何已安装字体的名称,但不枚举本地字体。 diff --git a/packages/client/ui-theme/package.json b/packages/client/ui-theme/package.json index 5c90ac94e1..669685f892 100644 --- a/packages/client/ui-theme/package.json +++ b/packages/client/ui-theme/package.json @@ -32,6 +32,7 @@ "inject": [ "@deepseek-ai/dsh-client-connection", "@deepseek-ai/dsh-client-locale", + "@deepseek-ai/dsh-client-shortcuts", "@deepseek-ai/dsh-client-ui-renderer", "@deepseek-ai/dsh-client-ui-settings", "@deepseek-ai/dsh-api-remotes" @@ -49,6 +50,7 @@ "@deepseek-ai/dsh-api-remotes": "workspace:*", "@deepseek-ai/dsh-client-connection": "workspace:*", "@deepseek-ai/dsh-client-locale": "workspace:*", + "@deepseek-ai/dsh-client-shortcuts": "workspace:*", "@deepseek-ai/dsh-client-store": "workspace:*", "@deepseek-ai/dsh-client-test-runtime": "workspace:*", "@deepseek-ai/dsh-client-ui-primitives": "workspace:*", diff --git a/packages/client/ui-theme/src/client/index.ts b/packages/client/ui-theme/src/client/index.ts index e2f47eb3bd..1e3c156e08 100644 --- a/packages/client/ui-theme/src/client/index.ts +++ b/packages/client/ui-theme/src/client/index.ts @@ -10,6 +10,7 @@ */ import type { Context as ClientContext } from '@deepseek-ai/cordis' import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots' +import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client' // Type-only: the ctx.configForms Context merge. Cross-plugin collaboration // goes through the service, never a value import (client bundle purity gate). import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client' @@ -480,7 +481,8 @@ export const inject = ['slots', 'locale', 'remote', 'configForms'] /** * Client plugin body: provide the theme service and register the * feature-owned Appearance and font settings rows into the General section's item - * slot (a feature owns its settings surface). + * slot (a feature owns its settings surface). Desktop font-size shortcuts share + * the text settings when the keyboard service is available. * @param ctx - client cordis context. */ export function apply(ctx: ClientContext): void { @@ -491,6 +493,32 @@ export function apply(ctx: ClientContext): void { ctx.effect(() => ctx.locale.register(SETTINGS_NS, { zh, en }), 'ui-theme: settings row dictionaries') + ctx.inject(['shortcuts'], (scope) => { + if (scope.shortcuts.runtime !== 'desktop') return + const t = scope.locale.bind(SETTINGS_NS) + for (const [direction, code] of [['increase', 'Equal'], ['decrease', 'Minus']] as const) { + const binding = { code, modifiers: ['primary'] as const } + const bindings = direction === 'increase' + ? [binding, { code, modifiers: ['primary', 'shift'] as const }] as const : [binding] as const + scope.effect(() => scope.shortcuts.registerFixed({ + id: `fontSize.${direction}` as ShortcutCommandId, label: () => t(`fontSize.text.${direction}`), + keys: scope.shortcuts.describeBinding(binding).keys.map(key => key === '=' ? '+' : key), + bindings, group: 'application', + }), `ui-theme: ${direction} font size reference`) + } + scope.effect(() => scope.shortcuts.observeFixedInput((input) => { + if (input.type === 'reset') return + const { gesture, context } = input + if (gesture.composing || gesture.defaultPrevented || gesture.repeat || context.region === 'terminal' + || gesture.alt || (scope.shortcuts.platform === 'macos' ? !gesture.meta || gesture.control : !gesture.control || gesture.meta) + || (gesture.code !== 'Equal' && gesture.code !== 'Minus') || (gesture.code === 'Minus' && gesture.shift)) return + input.consume() + const { min, max } = FONT_SIZE_SPECS.text + const delta = gesture.code === 'Equal' ? 1 : -1 + theme.setFontSize('text', Math.max(min, Math.min(max, theme.getTheme().fontSizes.text + delta))) + }), 'ui-theme: font size input') + }) + const store = createAppearanceRowStore() let bound: BoundActions | undefined const fontStore = createFontRowStore() diff --git a/packages/client/ui-theme/tests/apply.client.spec.ts b/packages/client/ui-theme/tests/apply.client.spec.ts index 9bb2ef9db0..7c63dfbfcc 100644 --- a/packages/client/ui-theme/tests/apply.client.spec.ts +++ b/packages/client/ui-theme/tests/apply.client.spec.ts @@ -2,7 +2,7 @@ * locale service, declaration-aware Appearance row registration, snapshot * projection into the row store, and HMR collapse recovery. */ import { Context } from '@deepseek-ai/cordis' -import { describe, expect, it, vi } from 'vitest' +import { describe, expect, it, onTestFinished, vi } from 'vitest' import { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client' import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client' import { TestRemote } from '@deepseek-ai/dsh-client-test-runtime' @@ -13,6 +13,9 @@ import { THEME_SETTINGS_NAMESPACE, ThemeSettingsSchema } from '../src/theme-sett import { AppearanceRow } from '../src/client/AppearanceRow.tsx' import type { createAppearanceRowStore, createFontRowStore } from '../src/client/settings-store.ts' import { FontSettingsGroup } from '../src/client/FontSettingsGroup.tsx' +import type { Shortcuts, ShortcutContext, ShortcutFixedInput, ShortcutGesture, ShortcutPlatform } from '@deepseek-ai/dsh-client-shortcuts/client' +import { bindingKey, normalizeBinding, presentBinding } from '@deepseek-ai/dsh-client-shortcuts/protocol' +import { ShortcutRegistry } from '../../shortcuts/src/client/registry.ts' // These specs assert the shipped Chinese copy. The lane has no jsdom `window`, // so browser-language detection never runs and a fresh LocaleRuntime opens on @@ -85,7 +88,142 @@ function fontSettingsFaceOf(slots: SlotRegistry) { return { entry, instance, face: face as FontSettingsInjected } } +/** Deliver the keyboard service's arbitrated input while keeping its real catalog and bindings. */ +function fontKeyboard(ctx: Context, runtime: Shortcuts['runtime'] = 'desktop', platform: ShortcutPlatform = 'macos') { + onTestFinished(() => ctx.fiber.dispose()) + const registry = new ShortcutRegistry(runtime, platform) + const listeners = new Set<(input: ShortcutFixedInput) => void>() + const shortcuts: Pick = { + runtime, platform, + registerFixed: command => registry.registerFixed(command), + describeBinding: (candidate) => { + const binding = candidate === null ? null : normalizeBinding(candidate, platform) + return { binding, keys: presentBinding(binding, platform).keys, issue: null, conflicts: [] } + }, + observeFixedInput: (listener) => { + listeners.add(listener) + return () => { listeners.delete(listener) } + }, + } + ctx.provide('shortcuts', shortcuts) + return { + registry, + press: (gesture: Partial = {}, context: Partial = {}) => { + const consume = vi.fn() + for (const listener of listeners) listener({ + type: 'keydown', consume, + gesture: { code: 'Equal', meta: platform === 'macos', control: platform !== 'macos', alt: false, + shift: false, repeat: false, composing: false, defaultPrevented: false, ...gesture }, + context: { region: 'page', modal: null, target: null, ...context }, + }) + return consume + }, + reset: () => { for (const listener of listeners) listener({ type: 'reset' }) }, + } +} + describe('ui-theme apply', () => { + it.each(['macos', 'windows', 'linux'] as const)('shares %s font shortcuts with the settings control and durable values', async (platform) => { + const b = await bench() + const keyboard = fontKeyboard(b.ctx, 'desktop', platform) + declareItems(b.slots) + const fiber = b.ctx.plugin({ inject: [...inject], apply }) + await fiber.await() + const theme = b.ctx.get('theme') as ThemeRuntime + const { instance, face } = fontSettingsFaceOf(b.slots) + + expect(keyboard.press()).toHaveBeenCalledOnce() + expect(theme.getTheme().fontSizes.text).toBe(15) + keyboard.press({ shift: true }, { region: 'editable' }) + expect(instance.getSnapshot().fontSizes.text).toBe(16) + keyboard.press({ code: 'Minus' }) + expect(instance.getSnapshot().fontSizes.text).toBe(15) + face.setFontSize('text', 20) + keyboard.press() + expect(theme.getTheme().fontSizes).toEqual({ text: 21, code: 11, terminal: 13 }) + await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(5) }) + expect(b.mutate.mock.calls.at(-1)?.[1][0]?.value).toBe(21) + + await fiber.dispose() + expect(keyboard.registry.fixedCatalog.getSnapshot()).toEqual([]) + expect(keyboard.press()).not.toHaveBeenCalled() + expect(theme.getTheme().fontSizes.text).toBe(21) + await b.ctx.fiber.dispose() + }) + + it('presents both desktop font actions with their accepted physical combinations', async () => { + const b = await bench() + const keyboard = fontKeyboard(b.ctx) + await b.ctx.plugin({ inject: [...inject], apply }).await() + expect(keyboard.registry.fixedCatalog.getSnapshot().map(row => ({ + label: row.label, keys: row.keys, bindings: row.bindings.map(bindingKey), + }))).toMatchInlineSnapshot(` + [ + { + "bindings": [ + "meta+Equal", + "shift+meta+Equal", + ], + "keys": [ + "⌘", + "+", + ], + "label": "增大字号", + }, + { + "bindings": [ + "meta+Minus", + ], + "keys": [ + "⌘", + "-", + ], + "label": "减小字号", + }, + ] + `) + await b.ctx.fiber.dispose() + }) + + it('consumes font shortcuts at either size limit without persisting another write', async () => { + const b = await bench() + const keyboard = fontKeyboard(b.ctx) + await b.ctx.plugin({ inject: [...inject], apply }).await() + const theme = b.ctx.get('theme') as ThemeRuntime + theme.setFontSize('text', 22) + await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledOnce() }) + expect(keyboard.press()).toHaveBeenCalledOnce() + expect(keyboard.press({ shift: true })).toHaveBeenCalledOnce() + theme.setFontSize('text', 10) + await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(2) }) + expect(keyboard.press({ code: 'Minus' })).toHaveBeenCalledOnce() + expect(theme.getTheme().fontSizes.text).toBe(10) + expect(b.mutate).toHaveBeenCalledTimes(2) + await b.ctx.fiber.dispose() + }) + + it('leaves browser zoom and locally owned input unchanged', async () => { + const browser = await bench() + const web = fontKeyboard(browser.ctx, 'web') + await browser.ctx.plugin({ inject: [...inject], apply }).await() + expect(web.registry.fixedCatalog.getSnapshot()).toEqual([]) + expect(web.press()).not.toHaveBeenCalled() + await browser.ctx.fiber.dispose() + + const b = await bench() + const keyboard = fontKeyboard(b.ctx) + await b.ctx.plugin({ inject: [...inject], apply }).await() + for (const gesture of [ + { composing: true }, { defaultPrevented: true }, { repeat: true }, { alt: true }, + { meta: false }, { control: true }, { code: 'KeyA' }, { code: 'Minus', shift: true }, + ]) expect(keyboard.press(gesture)).not.toHaveBeenCalled() + expect(keyboard.press({}, { region: 'terminal' })).not.toHaveBeenCalled() + keyboard.reset() + expect((b.ctx.get('theme') as ThemeRuntime).getTheme().fontSizes.text).toBe(14) + expect(b.mutate).not.toHaveBeenCalled() + await b.ctx.fiber.dispose() + }) + it('declares the slot and locale services', () => { expect(inject).toEqual(['slots', 'locale', 'remote', 'configForms']) }) diff --git a/packages/client/ui-theme/tsconfig.client.json b/packages/client/ui-theme/tsconfig.client.json index 1e68a788f4..5e56d362dc 100644 --- a/packages/client/ui-theme/tsconfig.client.json +++ b/packages/client/ui-theme/tsconfig.client.json @@ -15,6 +15,9 @@ { "path": "../locale/tsconfig.client.json" }, + { + "path": "../shortcuts/tsconfig.client.json" + }, { "path": "../store" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 146a58fe8e..0243d99eb8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5837,6 +5837,9 @@ importers: '@deepseek-ai/dsh-client-locale': specifier: workspace:* version: link:../locale + '@deepseek-ai/dsh-client-shortcuts': + specifier: workspace:* + version: link:../shortcuts '@deepseek-ai/dsh-client-store': specifier: workspace:* version: link:../store From 0c6968b649daa661da9a69e2f58358f017b6a191 Mon Sep 17 00:00:00 2001 From: fz Date: Tue, 13 Oct 2026 00:21:55 +0800 Subject: [PATCH 2/4] feat(web): adjust desktop font sizes together --- .../shortcuts-desktop/font-sizes.expected.md | 34 ++++++ apps/web/tests/shortcuts-desktop.e2e.ts | 65 ++++++++++- .../guide.i18n.yaml | 16 +++ .../desktop-font-size-shortcuts/guide.md | 18 ++++ .../desktop-font-size-shortcuts/guide.zh.md | 18 ++++ packages/client/ui-theme/README.i18n.yaml | 4 +- packages/client/ui-theme/README.md | 2 +- packages/client/ui-theme/README.zh.md | 2 +- packages/client/ui-theme/src/client/index.ts | 97 ++++++++++------- .../ui-theme/tests/apply.client.spec.ts | 102 +++++++++++++++--- .../src/client/api-catalog.ts | 2 +- 11 files changed, 300 insertions(+), 60 deletions(-) create mode 100644 apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md create mode 100644 docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.i18n.yaml create mode 100644 docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.md create mode 100644 docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.zh.md diff --git a/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md b/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md new file mode 100644 index 0000000000..3ab8133eda --- /dev/null +++ b/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md @@ -0,0 +1,34 @@ +# Font sizes + +{ + "initial": { + "text": 14, + "code": 11, + "terminal": 13 + }, + "afterEqual": { + "text": 15, + "code": 12, + "terminal": 14 + }, + "afterPlus": { + "text": 16, + "code": 13, + "terminal": 15 + }, + "afterMinus": { + "text": 15, + "code": 12, + "terminal": 14 + }, + "afterReload": { + "text": 15, + "code": 12, + "terminal": 14 + }, + "restored": { + "text": 14, + "code": 11, + "terminal": 13 + } +} diff --git a/apps/web/tests/shortcuts-desktop.e2e.ts b/apps/web/tests/shortcuts-desktop.e2e.ts index 9609e02de8..d70b492133 100644 --- a/apps/web/tests/shortcuts-desktop.e2e.ts +++ b/apps/web/tests/shortcuts-desktop.e2e.ts @@ -9,7 +9,7 @@ import { SessionId } from '@deepseek-ai/dsh-session' import { initialShortcutConfig, parseShortcutDefinitions, parseShortcutEdit } from '@deepseek-ai/dsh-client-shortcuts/protocol' import type { DesktopShortcutInput, DesktopShortcutsApi, ShortcutCommandId, ShortcutRevision } from '@deepseek-ai/dsh-client-shortcuts/protocol' import { desktopKeybindings } from '../../desktop/src/keybindings.ts' -import { compareOrRefreshGolden, launchWebScaffold, seedSession, watchConsole, webSnapshotMode } from './scaffold.ts' +import { acknowledgeReloadConnectionLoss, compareOrRefreshGolden, launchWebScaffold, seedSession, watchConsole, webSnapshotMode } from './scaffold.ts' import { writeComposerDraft } from './support.ts' declare global { @@ -63,6 +63,12 @@ it.each([ } }) }, marker) const console = watchConsole(page) + const fontMutations: unknown[][] = [] + page.on('request', (request) => { + if (new URL(request.url()).pathname !== '/api/settings/mutate' || request.method() !== 'POST') return + const input = request.postDataJSON() as { payload: { args: { ns: string; ops: unknown[] } } } + if (input.payload.args.ns === 'ui-theme') fontMutations.push(input.payload.args.ops) + }) await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) const deliverPrimary = (code: string, alt = false) => page.evaluate((input) => { window.shortcutFixture.deliver(input) @@ -131,6 +137,54 @@ it.each([ expect(await composer.innerText()).toBe('Desktop focus draft') await writeComposerDraft(page, composer, '') await expect.poll(() => composer.textContent()).toBe('') + const readFontSizes = () => page.evaluate(() => { + const style = document.body.style + return { + text: Number.parseInt(style.getPropertyValue('--dsh-content-font-size'), 10), + code: Number.parseInt(style.getPropertyValue('--dsh-code-font-size'), 10), + terminal: Number.parseInt(style.getPropertyValue('--dsh-terminal-font-size'), 10), + } + }) + const defaults = { text: 14, code: 11, terminal: 13 } + const patchPath = join(scaffold.harnessHome, 'profiles', 'scaffold', 'cordis.patch.yml') + const stepFontSizes = async (key: string, sizes: Awaited>): Promise => { + const before = fontMutations.length + const [response] = await Promise.all([ + page.waitForResponse((reply) => { + if (new URL(reply.url()).pathname !== '/api/settings/mutate' || reply.request().method() !== 'POST') return false + const input = reply.request().postDataJSON() as { payload: { args: { ns: string } } } + return input.payload.args.ns === 'ui-theme' + }), + page.keyboard.press(key), + ]) + expect(await response.finished()).toBeNull() + const envelope = await response.json() as { result: { ok: boolean } } + expect(envelope.result.ok).toBe(true) + const fields = [['fontSize', sizes.text], ['codeFontSize', sizes.code], ['terminalFontSize', sizes.terminal]] as const + expect(fontMutations.slice(before)).toEqual([fields.map(([field, value]) => ({ op: 'set', path: [field], value }))]) + await expect.poll(readFontSizes).toEqual(sizes) + for (const [field, value] of fields) { + await expect.poll(() => readFile(patchPath, 'utf8')).toContain(`${field}: ${value}`) + } + } + const initial = await readFontSizes() + expect(initial).toEqual(defaults) + await stepFontSizes(`${primary}+Equal`, { text: 15, code: 12, terminal: 14 }) + const afterEqual = await readFontSizes() + await stepFontSizes(`${primary}+Shift+Equal`, { text: 16, code: 13, terminal: 15 }) + const afterPlus = await readFontSizes() + await stepFontSizes(`${primary}+Minus`, { text: 15, code: 12, terminal: 14 }) + const afterMinus = await readFontSizes() + const warningStart = console.warnings.length + await page.reload({ waitUntil: 'load' }) + acknowledgeReloadConnectionLoss(console, warningStart) + await page.getByText('DONE', { exact: true }).waitFor() + await expect.poll(readFontSizes).toEqual(afterMinus) + const afterReload = await readFontSizes() + await composer.focus() + await stepFontSizes(`${primary}+Minus`, defaults) + await compareOrRefreshGolden(join(expected, 'font-sizes.expected.md'), + `# Font sizes\n\n${JSON.stringify({ initial, afterEqual, afterPlus, afterMinus, afterReload, restored: await readFontSizes() }, null, 2)}`, mode) const dialog = page.getByRole('dialog', { name: 'Keyboard shortcuts', exact: true }) const settings = page.getByRole('dialog', { name: 'Settings', exact: true }) const automaticFocusStyle = () => page.evaluate(() => { @@ -299,7 +353,8 @@ it.each([ await expect.poll(() => recorder.isEnabled()).toBe(true) await recorder.focus() const accepted = snapshot.document - for (const key of [`${primary}+Slash`, 'Escape', 'Enter', 'ArrowUp', 'ArrowDown', 'Shift+Enter', `${primary}+Enter`, 'Slash', 'Shift+Digit2']) { + const mutationsBeforeRecording = fontMutations.length + for (const key of [`${primary}+Equal`, `${primary}+Shift+Equal`, `${primary}+Minus`, `${primary}+Slash`, 'Escape', 'Enter', 'ArrowUp', 'ArrowDown', 'Shift+Enter', `${primary}+Enter`, 'Slash', 'Shift+Digit2']) { expect(await recorder.evaluate(node => node === document.activeElement)).toBe(true) const keys = key.split('+') for (const held of keys) await page.keyboard.down(held) @@ -310,6 +365,12 @@ it.each([ if (key === `${primary}+Slash`) { await dialog.getByText('Already used by “Open keyboard shortcuts”', { exact: true }).waitFor() } + if (key.endsWith('Equal') || key.endsWith('Minus')) { + const command = key.endsWith('Minus') ? 'Decrease font size' : 'Increase font size' + await dialog.getByText(`Already used by “${command}”`, { exact: true }).waitFor() + } + expect(await readFontSizes()).toEqual(defaults) + expect(fontMutations).toHaveLength(mutationsBeforeRecording) expect(await recorder.evaluate(node => node === document.activeElement)).toBe(true) expect(snapshot.document).toEqual(accepted) expect(await dialog.getByRole('listitem').evaluateAll(rows => rows.map(row => row.getBoundingClientRect().height))) diff --git a/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.i18n.yaml b/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.i18n.yaml new file mode 100644 index 0000000000..a4a47e22a2 --- /dev/null +++ b/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.i18n.yaml @@ -0,0 +1,16 @@ +# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading +# section, a hash of its English and Chinese blocks outside code blocks and generated regions. +# After editing either side, bring the other along and re-record with: +# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.md +/: + en: 0863e2ef201c6e98 + zh: e7042cab4852e9c8 +/desktop-font-size-shortcuts-reserve-custom-key-combinations: + en: 7c82d9faadaec1e0 + zh: 91d60eb7a660e1b3 +/desktop-font-size-shortcuts-reserve-custom-key-combinations/change: + en: cb025eb9ae5e18ae + zh: 094ec608c1ce4dad +/desktop-font-size-shortcuts-reserve-custom-key-combinations/migration: + en: bc66077939ee3df3 + zh: f8460bf5ec20ac58 diff --git a/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.md b/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.md new file mode 100644 index 0000000000..f674031611 --- /dev/null +++ b/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.md @@ -0,0 +1,18 @@ +--- +kind: upgrade-guide +description: "Desktop font-size shortcuts reserve key combinations previously available to custom shortcuts." +--- + +# Desktop font-size shortcuts reserve custom key combinations + +English | [中文](guide.zh.md) + +## Change + +Desktop reserves `Cmd`/`Ctrl` + `=` (including `Shift` + `=` for `+`) and `Cmd`/`Ctrl` + `-` to adjust text, code, and terminal font sizes together. Use `Cmd` on macOS and `Ctrl` on Windows and Linux. Custom bindings using these combinations, including overlapping two-key chords, remain saved but no longer execute. Web shortcut behavior is unchanged. + +## Migration + +1. Open Settings → General → Keyboard shortcuts in Desktop and find any custom binding marked as conflicting with a font-size shortcut. +2. Record a nonconflicting combination for that action, or choose **Remove** to disable its keyboard shortcut. **Restore default** is available when the action's default does not conflict. +3. Try the reassigned action, then press `Cmd`/`Ctrl` + `=` and `Cmd`/`Ctrl` + `-`. Confirm that all three font sizes change in Settings and remain saved after reopening Desktop. diff --git a/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.zh.md b/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.zh.md new file mode 100644 index 0000000000..a9d052744f --- /dev/null +++ b/docs/upgrade-guide/v0.2.1-alpha.2/desktop-font-size-shortcuts/guide.zh.md @@ -0,0 +1,18 @@ +--- +kind: upgrade-guide +description: "桌面端字号快捷键占用了原先可用于自定义快捷键的组合键。" +--- + +# 桌面端字号快捷键占用部分自定义组合键 + +[English](guide.md) | 中文 + +## 变更 + +桌面端保留 `Cmd`/`Ctrl` + `=`(包括输入 `+` 的 `Shift` + `=`)和 `Cmd`/`Ctrl` + `-`,用于一起调整正文、代码和终端字号。macOS 使用 `Cmd`,Windows 和 Linux 使用 `Ctrl`。使用这些组合键的自定义绑定,包括与其重叠的双键序列,仍会保存,但不再执行。Web 端快捷键行为不变。 + +## 迁移 + +1. 在桌面端打开「设置 → 通用 → 键盘快捷键」,找到标记为与字号快捷键冲突的自定义绑定。 +2. 为该操作录制不冲突的组合键,或选择「移除」禁用其快捷键。操作的默认快捷键不冲突时,也可以选择「恢复默认」。 +3. 尝试重新绑定的操作,再按 `Cmd`/`Ctrl` + `=` 和 `Cmd`/`Ctrl` + `-`。确认设置中的三组字号一起变化,并在重新打开桌面端后仍保留。 diff --git a/packages/client/ui-theme/README.i18n.yaml b/packages/client/ui-theme/README.i18n.yaml index 9544d10046..18476789c5 100644 --- a/packages/client/ui-theme/README.i18n.yaml +++ b/packages/client/ui-theme/README.i18n.yaml @@ -18,8 +18,8 @@ en: 5a279269e31713c1 zh: dcd5c31fbdfd63e2 /deepseek-ai-dsh-client-ui-theme/use-this-package/appearance-and-font-size: - en: b1355dc143f22d2f - zh: a288c70c1fc73704 + en: ce7888c9f8ca8b9a + zh: 829e0ce1a6cb8ac6 /deepseek-ai-dsh-client-ui-theme/use-this-package/fonts: en: b45d5b48ca799c3a zh: af65514b3759204f diff --git a/packages/client/ui-theme/README.md b/packages/client/ui-theme/README.md index 2103890cca..8c0e05825b 100644 --- a/packages/client/ui-theme/README.md +++ b/packages/client/ui-theme/README.md @@ -31,7 +31,7 @@ Users switch the color scheme, font sizes, and fonts from rows in Settings (Gene The plugin registers Appearance preference cubes and the text font-size stepper in the General section. A More font settings button after the stepper expands a region below it, collapsed on every settings open, with a font row for each of text, code, and the terminal, plus the code and terminal font-size steppers. The text stepper accepts integer values from 10 through 22 px and defaults to 14 px. It changes conversation headings and base text by the same increment, including the user bubble and composer draft; flow-row titles, summaries, and tables follow one step under the body size, while small text keeps a fixed size. The code stepper (10–16 px, default 11) sets the code-block size; inline code stays 1 px larger, and the small tool-output variant uses the same size. The terminal stepper (10–20 px, default 13) sets the sidebar terminal cell font size; changing it keeps the shell and output and refits the grid. Each accepted change writes through the Host settings API. Rapid changes serialize in gesture order with namespace revisions, and a rejected latest write reloads the durable values. -Desktop's fixed `Cmd`/`Ctrl` + `+` (or `=`) and `Cmd`/`Ctrl` + `-` shortcuts change the text size by 1 px through the same setting, within 10–22 px. They appear in the shortcut reference and work in the main page and its text inputs; terminal input retains its own key handling. Web retains the browser's zoom shortcuts. +Desktop's fixed `Cmd`/`Ctrl` + `+` (or `=`) and `Cmd`/`Ctrl` + `-` shortcuts change the text, code, and terminal font sizes together by 1 px, each within its own range. Each physical key press saves the changed fields in one settings mutation. The actions appear in the shortcut reference and work in the main document, including dialogs and text inputs, unless a local control consumes the input; terminal input retains its own key handling. Web retains the browser's zoom shortcuts. ### Fonts diff --git a/packages/client/ui-theme/README.zh.md b/packages/client/ui-theme/README.zh.md index 81b5a09d89..add05ecc38 100644 --- a/packages/client/ui-theme/README.zh.md +++ b/packages/client/ui-theme/README.zh.md @@ -31,7 +31,7 @@ kind: "package-reference" 插件在「通用」分区注册外观偏好方块与正文字号步进器。步进器后的「更多字体设置」按钮在其下方展开一个区域,每次打开设置时均为折叠状态,其中包含正文、代码与终端各自的字体行,以及代码与终端的字号步进器。正文步进器接受 10 至 22 px 的整数,默认值为 14 px。它以相同增量调整会话标题与基础文本,包括用户气泡与 composer 草稿;流内行的标题、摘要与表格跟随比正文低一档的字号,小号文本保持固定字号。代码步进器(10–16 px,默认 11)设置代码块字号;行内代码保持大 1 px,工具输出的小号变体使用相同字号。终端步进器(10–20 px,默认 13)设置侧栏终端的单元格字号;修改后保留 shell 与输出,并重新适配网格。每次通过的变更都经 Host settings API 写入。连续快速变更按操作顺序携带命名空间 revision 串行写入,最新写入被拒时重新加载持久值。 -Desktop 的固定快捷键 `Cmd`/`Ctrl` + `+`(或 `=`)和 `Cmd`/`Ctrl` + `-` 通过同一设置每次增减 1 px,范围为 10–22 px。它们显示在快捷键参考中,可在主页面及其文本输入框内使用;终端输入保留自身的按键处理。Web 保留浏览器的缩放快捷键。 +Desktop 的固定快捷键 `Cmd`/`Ctrl` + `+`(或 `=`)和 `Cmd`/`Ctrl` + `-` 同时将正文、代码与终端字号增减 1 px,各自沿用其取值范围。每次实际按下按键,通过一次设置操作保存变化字段。这些操作显示在快捷键参考中,可在主文档的对话框和文本输入框内使用,但会让已消费输入的本地控件先处理;终端输入保留自身的按键处理。Web 保留浏览器的缩放快捷键。 ### 字体 diff --git a/packages/client/ui-theme/src/client/index.ts b/packages/client/ui-theme/src/client/index.ts index 1e3c156e08..9db94a50e3 100644 --- a/packages/client/ui-theme/src/client/index.ts +++ b/packages/client/ui-theme/src/client/index.ts @@ -6,7 +6,7 @@ * settings scope loads and stores the preference in the user-settings * document. The plugin also registers the Appearance and font settings rows * into the settings General section — the theme feature owns its own settings - * surface. + * surface. Desktop shortcuts adjust text, code, and terminal font sizes together. */ import type { Context as ClientContext } from '@deepseek-ai/cordis' import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots' @@ -202,6 +202,7 @@ export class ThemeRuntime { } ctx.effect(() => host.subscribe(() => { this.adopt() }), 'ui-theme: settings scope adoption') this.adopt() + installFontSizeShortcuts(ctx, (delta) => { this.adjustFontSizes(delta) }) } /** @@ -243,12 +244,12 @@ export class ThemeRuntime { } if (this.preference === id) return this.preference = id as ThemePreference - if (isThemePreference(id)) this.write(THEME_PREFERENCE_FIELD, id) + if (isThemePreference(id)) this.write(() => this.host.set(THEME_PREFERENCE_FIELD, id)) this.publish() } /** - * Change one role's font size — the only font-size write entry. Accepted + * Change one role's font size. Accepted * values are written through the settings scope and emit `theme/change`. * @param role - font role. * @param px - integer px within the role's `FONT_SIZE_SPECS` range; out-of-range or fractional values throw. @@ -258,7 +259,29 @@ export class ThemeRuntime { if (!isFontSize(role, px)) throw new Error(`${role} font size ${px} is outside ${spec.min}..${spec.max}`) if (this.fontSizes[role] === px) return this.fontSizes = Object.freeze({ ...this.fontSizes, [role]: px }) - this.write(spec.field, px) + this.write(() => this.host.set(spec.field, px)) + this.publish() + } + + /** + * Step all font sizes within their own ranges and save changed fields in one mutation. + * Emits one `theme/change`; no write or event occurs when every role is at its limit. + * @param delta - one pixel to add or remove from each role's current size. + */ + private adjustFontSizes(delta: 1 | -1): void { + const fontSizes = { ...this.fontSizes } + const fields: Record = {} + for (const role of FONT_ROLES) { + const { field, min, max } = FONT_SIZE_SPECS[role] + const px = Math.max(min, Math.min(max, fontSizes[role] + delta)) + if (px === fontSizes[role]) continue + fontSizes[role] = px + fields[field] = px + } + const ops = Object.entries(fields).map(([field, value]) => ({ op: 'set' as const, path: [field], value })) + if (ops.length === 0) return + this.fontSizes = Object.freeze(fontSizes) + this.write(() => this.host.mutate(ops)) this.publish() } @@ -273,14 +296,14 @@ export class ThemeRuntime { const list = normalizeFontFamily(value) if (this.fontFamilies[role] === list) return this.fontFamilies = Object.freeze({ ...this.fontFamilies, [role]: list }) - this.write(FONT_FAMILY_FIELDS[role], list) + this.write(() => this.host.set(FONT_FAMILY_FIELDS[role], list)) this.publish() } - /** Write one field through the settings scope, then adopt the durable section once no own write remains. */ - private write(field: string, value: string | number): void { + /** Queue one settings write, then adopt the durable section once no own write remains. */ + private write(operation: () => Promise): void { this.pendingWrites += 1 - void this.host.set(field, value).finally(() => { + void operation().finally(() => { this.pendingWrites -= 1 this.adopt() }) @@ -471,6 +494,33 @@ function dynamicToken(name: string): ThemeTokenInspection { } } +/** Register desktop font-size keys when keyboard and locale services are available. */ +function installFontSizeShortcuts(ctx: ClientContext, adjust: (delta: 1 | -1) => void): void { + ctx.inject(['shortcuts', 'locale'], (scope) => { + if (scope.shortcuts.runtime !== 'desktop') return + const t = scope.locale.bind(SETTINGS_NS) + for (const [direction, code] of [['increase', 'Equal'], ['decrease', 'Minus']] as const) { + const binding = { code, modifiers: ['primary'] as const } + const bindings = direction === 'increase' + ? [binding, { code, modifiers: ['primary', 'shift'] as const }] as const : [binding] as const + scope.effect(() => scope.shortcuts.registerFixed({ + id: `fontSize.${direction}` as ShortcutCommandId, label: () => t(`fontSize.text.${direction}`), + keys: scope.shortcuts.describeBinding(binding).keys, + bindings, group: 'application', + }), `ui-theme: ${direction} font size reference`) + } + scope.effect(() => scope.shortcuts.observeFixedInput((input) => { + if (input.type === 'reset') return + const { gesture, context } = input + if (gesture.composing || gesture.defaultPrevented || gesture.repeat || context.region === 'terminal' + || gesture.alt || (scope.shortcuts.platform === 'macos' ? !gesture.meta || gesture.control : !gesture.control || gesture.meta) + || (gesture.code !== 'Equal' && gesture.code !== 'Minus') || (gesture.code === 'Minus' && gesture.shift)) return + input.consume() + adjust(gesture.code === 'Equal' ? 1 : -1) + }), 'ui-theme: font size input') + }) +} + /** * Required services: settings transport plus slots/locale for the Appearance * row. `remote` carries the forwarded settings invalidation that @@ -482,43 +532,16 @@ export const inject = ['slots', 'locale', 'remote', 'configForms'] * Client plugin body: provide the theme service and register the * feature-owned Appearance and font settings rows into the General section's item * slot (a feature owns its settings surface). Desktop font-size shortcuts share - * the text settings when the keyboard service is available. + * all three font-size settings when the keyboard service is available. * @param ctx - client cordis context. */ export function apply(ctx: ClientContext): void { installThemeStyles(ctx) + ctx.effect(() => ctx.locale.register(SETTINGS_NS, { zh, en }), 'ui-theme: settings row dictionaries') const host = ctx.configForms.get(THEME_SETTINGS_NAMESPACE) const theme = new ThemeRuntime(ctx, host) ctx.provide('theme', theme) - ctx.effect(() => ctx.locale.register(SETTINGS_NS, { zh, en }), 'ui-theme: settings row dictionaries') - - ctx.inject(['shortcuts'], (scope) => { - if (scope.shortcuts.runtime !== 'desktop') return - const t = scope.locale.bind(SETTINGS_NS) - for (const [direction, code] of [['increase', 'Equal'], ['decrease', 'Minus']] as const) { - const binding = { code, modifiers: ['primary'] as const } - const bindings = direction === 'increase' - ? [binding, { code, modifiers: ['primary', 'shift'] as const }] as const : [binding] as const - scope.effect(() => scope.shortcuts.registerFixed({ - id: `fontSize.${direction}` as ShortcutCommandId, label: () => t(`fontSize.text.${direction}`), - keys: scope.shortcuts.describeBinding(binding).keys.map(key => key === '=' ? '+' : key), - bindings, group: 'application', - }), `ui-theme: ${direction} font size reference`) - } - scope.effect(() => scope.shortcuts.observeFixedInput((input) => { - if (input.type === 'reset') return - const { gesture, context } = input - if (gesture.composing || gesture.defaultPrevented || gesture.repeat || context.region === 'terminal' - || gesture.alt || (scope.shortcuts.platform === 'macos' ? !gesture.meta || gesture.control : !gesture.control || gesture.meta) - || (gesture.code !== 'Equal' && gesture.code !== 'Minus') || (gesture.code === 'Minus' && gesture.shift)) return - input.consume() - const { min, max } = FONT_SIZE_SPECS.text - const delta = gesture.code === 'Equal' ? 1 : -1 - theme.setFontSize('text', Math.max(min, Math.min(max, theme.getTheme().fontSizes.text + delta))) - }), 'ui-theme: font size input') - }) - const store = createAppearanceRowStore() let bound: BoundActions | undefined const fontStore = createFontRowStore() diff --git a/packages/client/ui-theme/tests/apply.client.spec.ts b/packages/client/ui-theme/tests/apply.client.spec.ts index 7c63dfbfcc..877ce818c3 100644 --- a/packages/client/ui-theme/tests/apply.client.spec.ts +++ b/packages/client/ui-theme/tests/apply.client.spec.ts @@ -5,11 +5,11 @@ import { Context } from '@deepseek-ai/cordis' import { describe, expect, it, onTestFinished, vi } from 'vitest' import { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client' import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client' -import { TestRemote } from '@deepseek-ai/dsh-client-test-runtime' +import { TestRemote, stubConfigForm } from '@deepseek-ai/dsh-client-test-runtime' import { apply as settingsApply, inject as settingsInject } from '@deepseek-ai/dsh-client-ui-settings/client' -import { apply, inject, SETTINGS_NS } from '@deepseek-ai/dsh-client-ui-theme/client' -import type { AppearanceRowInjected, FontSettingsInjected, ThemeRuntime } from '@deepseek-ai/dsh-client-ui-theme/client' -import { THEME_SETTINGS_NAMESPACE, ThemeSettingsSchema } from '../src/theme-settings.ts' +import { apply, inject, SETTINGS_NS, ThemeRuntime } from '@deepseek-ai/dsh-client-ui-theme/client' +import type { AppearanceRowInjected, FontSettingsInjected, ThemeSnapshot } from '@deepseek-ai/dsh-client-ui-theme/client' +import { THEME_SETTINGS_NAMESPACE, ThemeSettingsSchema, type ThemeSettings } from '../src/theme-settings.ts' import { AppearanceRow } from '../src/client/AppearanceRow.tsx' import type { createAppearanceRowStore, createFontRowStore } from '../src/client/settings-store.ts' import { FontSettingsGroup } from '../src/client/FontSettingsGroup.tsx' @@ -49,8 +49,7 @@ async function bench(isLoopback = true) { value: { writable: true, hasDocument: true, namespaces: [namespace()] }, })) const mutate = vi.fn((_ns: string, ops: { path: string[]; value: unknown }[]) => { - const op = ops[0]! - section[op.path[0]!] = op.value + for (const op of ops) section[op.path[0]!] = op.value return Promise.resolve({ ok: true as const, value: namespace() }) }) const events = new TestRemote(ctx, { settings: { describe, mutate } }) @@ -122,7 +121,69 @@ function fontKeyboard(ctx: Context, runtime: Shortcuts['runtime'] = 'desktop', p } } +/** Isolate theme write outcomes behind the same registered keyboard input. */ +async function keyboardTheme(host = stubConfigForm()) { + const ctx = new Context() + ctx.provide('locale', new LocaleRuntime(ctx)) + const keyboard = fontKeyboard(ctx) + const events: ThemeSnapshot[] = [] + ctx.on('theme/change', (snapshot) => { events.push(snapshot) }) + await ctx.plugin({ apply: (scope) => { + scope.provide('theme', new ThemeRuntime(scope, host.scope)) + } }).await() + return { theme: ctx.get('theme') as ThemeRuntime, keyboard, events, host } +} + describe('ui-theme apply', () => { + it('steps all font sizes in one settings mutation and one snapshot', async () => { + const { theme, keyboard, events, host } = await keyboardTheme() + keyboard.press() + expect(theme.getTheme().fontSizes).toEqual({ text: 15, code: 12, terminal: 14 }) + expect(host.mutate).toHaveBeenCalledExactlyOnceWith([ + { op: 'set', path: ['fontSize'], value: 15 }, + { op: 'set', path: ['codeFontSize'], value: 12 }, + { op: 'set', path: ['terminalFontSize'], value: 14 }, + ]) + expect(host.set).not.toHaveBeenCalled() + expect(events).toHaveLength(1) + expect(events[0]?.fontSizes).toEqual({ text: 15, code: 12, terminal: 14 }) + }) + + it('continues stepping other font roles when one has reached its own limit', async () => { + const { theme, keyboard, host } = await keyboardTheme() + theme.setFontSize('text', 22) + theme.setFontSize('code', 10) + theme.setFontSize('terminal', 20) + keyboard.press() + expect(theme.getTheme().fontSizes).toEqual({ text: 22, code: 11, terminal: 20 }) + expect(host.mutate).toHaveBeenCalledExactlyOnceWith([ + { op: 'set', path: ['codeFontSize'], value: 11 }, + ]) + keyboard.press({ code: 'Minus' }) + expect(theme.getTheme().fontSizes).toEqual({ text: 21, code: 10, terminal: 19 }) + keyboard.press({ code: 'Minus' }) + expect(theme.getTheme().fontSizes).toEqual({ text: 20, code: 10, terminal: 18 }) + expect(host.mutate).toHaveBeenLastCalledWith([ + { op: 'set', path: ['fontSize'], value: 20 }, + { op: 'set', path: ['terminalFontSize'], value: 18 }, + ]) + }) + + it('adopts all durable font sizes together after a refused batch settles', async () => { + const host = stubConfigForm() + const section: ThemeSettings = { preference: 'system', fontSize: 14, codeFontSize: 11, terminalFontSize: 13, + textFontFamily: '', codeFontFamily: '', terminalFontFamily: '' } + host.publish({ status: 'ready', value: section, revision: 1, writable: true }) + const { theme, keyboard } = await keyboardTheme(host) + const write = Promise.withResolvers() + host.mutate.mockReturnValue(write.promise) + keyboard.press() + host.publish({ value: section, revision: 2 }) + expect(theme.getTheme().fontSizes).toEqual({ text: 15, code: 12, terminal: 14 }) + write.resolve(false) + await vi.waitFor(() => { expect(theme.getTheme().fontSizes).toEqual({ text: 14, code: 11, terminal: 13 }) }) + }) + it.each(['macos', 'windows', 'linux'] as const)('shares %s font shortcuts with the settings control and durable values', async (platform) => { const b = await bench() const keyboard = fontKeyboard(b.ctx, 'desktop', platform) @@ -133,16 +194,21 @@ describe('ui-theme apply', () => { const { instance, face } = fontSettingsFaceOf(b.slots) expect(keyboard.press()).toHaveBeenCalledOnce() - expect(theme.getTheme().fontSizes.text).toBe(15) + expect(theme.getTheme().fontSizes).toEqual({ text: 15, code: 12, terminal: 14 }) keyboard.press({ shift: true }, { region: 'editable' }) - expect(instance.getSnapshot().fontSizes.text).toBe(16) + expect(instance.getSnapshot().fontSizes).toEqual({ text: 16, code: 13, terminal: 15 }) keyboard.press({ code: 'Minus' }) - expect(instance.getSnapshot().fontSizes.text).toBe(15) + expect(instance.getSnapshot().fontSizes).toEqual({ text: 15, code: 12, terminal: 14 }) face.setFontSize('text', 20) keyboard.press() - expect(theme.getTheme().fontSizes).toEqual({ text: 21, code: 11, terminal: 13 }) + expect(theme.getTheme().fontSizes).toEqual({ text: 21, code: 13, terminal: 15 }) await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(5) }) - expect(b.mutate.mock.calls.at(-1)?.[1][0]?.value).toBe(21) + expect(b.mutate.mock.calls.at(-1)?.[1]).toEqual([ + { op: 'set', path: ['fontSize'], value: 21 }, + { op: 'set', path: ['codeFontSize'], value: 13 }, + { op: 'set', path: ['terminalFontSize'], value: 15 }, + ]) + expect(theme.getTheme().fontSizes).toEqual({ text: 21, code: 13, terminal: 15 }) await fiber.dispose() expect(keyboard.registry.fixedCatalog.getSnapshot()).toEqual([]) @@ -166,7 +232,7 @@ describe('ui-theme apply', () => { ], "keys": [ "⌘", - "+", + "=", ], "label": "增大字号", }, @@ -191,14 +257,18 @@ describe('ui-theme apply', () => { await b.ctx.plugin({ inject: [...inject], apply }).await() const theme = b.ctx.get('theme') as ThemeRuntime theme.setFontSize('text', 22) - await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledOnce() }) + theme.setFontSize('code', 16) + theme.setFontSize('terminal', 20) + await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(3) }) expect(keyboard.press()).toHaveBeenCalledOnce() expect(keyboard.press({ shift: true })).toHaveBeenCalledOnce() theme.setFontSize('text', 10) - await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(2) }) + theme.setFontSize('code', 10) + theme.setFontSize('terminal', 10) + await vi.waitFor(() => { expect(b.mutate).toHaveBeenCalledTimes(6) }) expect(keyboard.press({ code: 'Minus' })).toHaveBeenCalledOnce() - expect(theme.getTheme().fontSizes.text).toBe(10) - expect(b.mutate).toHaveBeenCalledTimes(2) + expect(theme.getTheme().fontSizes).toEqual({ text: 10, code: 10, terminal: 10 }) + expect(b.mutate).toHaveBeenCalledTimes(6) await b.ctx.fiber.dispose() }) diff --git a/packages/extensions/cordis-client-runner/src/client/api-catalog.ts b/packages/extensions/cordis-client-runner/src/client/api-catalog.ts index 469db60766..6a1c9afeec 100644 --- a/packages/extensions/cordis-client-runner/src/client/api-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/api-catalog.ts @@ -276,7 +276,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [ }, { signature: 'setFontSize(role: FontRole, px: number): void', - description: 'Change one role\'s font size — the only font-size write entry. Accepted values are written through the settings scope and emit `theme/change`.', + description: 'Change one role\'s font size. Accepted values are written through the settings scope and emit `theme/change`.', parameters: [{ name: 'role', description: 'font role.' }, { name: 'px', description: 'integer px within the role\'s `FONT_SIZE_SPECS` range; out-of-range or fractional values throw.' }], }, { From cd5d5bc7bd18f3843c9136be2dec45af06c9df77 Mon Sep 17 00:00:00 2001 From: fz Date: Tue, 13 Oct 2026 00:50:08 +0800 Subject: [PATCH 3/4] test(web): await sidebar collapse before measuring plugin header --- .../expected/plugin-manager/header-responsive.expected.md | 2 +- apps/web/tests/plugin-manager.e2e.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/web/tests/expected/plugin-manager/header-responsive.expected.md b/apps/web/tests/expected/plugin-manager/header-responsive.expected.md index 956ddbda34..73723e7184 100644 --- a/apps/web/tests/expected/plugin-manager/header-responsive.expected.md +++ b/apps/web/tests/expected/plugin-manager/header-responsive.expected.md @@ -1,7 +1,7 @@ # Plugin header responsive layout en 1680px: actions beside the heading, single-line; contained; information follows subtitle; focus retained -en 768px: actions below the heading, single-line; contained; information follows subtitle; focus retained +en 768px: actions beside the heading, single-line; contained; information follows subtitle; focus retained en 520px: actions below the heading, single-line; contained; information follows subtitle; focus retained en 440px: actions below the heading, single-line; contained; information follows subtitle; focus retained en 390px: actions below the heading, single-line; contained; information follows subtitle; focus retained diff --git a/apps/web/tests/plugin-manager.e2e.ts b/apps/web/tests/plugin-manager.e2e.ts index 15937b97ff..929ee5dafa 100644 --- a/apps/web/tests/plugin-manager.e2e.ts +++ b/apps/web/tests/plugin-manager.e2e.ts @@ -125,8 +125,11 @@ describe('web e2e: plugin manager', () => { const add = header.getByRole('button', { name: language === 'en' ? 'Add plugin' : '添加插件', exact: true }) await expect.poll(() => add.isEnabled()).toBe(true) await add.focus() + const frame = probe.locator('[data-shell-bottom]').locator('..') for (const width of [1680, 768, 520, 440, 390, 430, 1024]) { await probe.setViewportSize({ width, height: 1000 }) + // The responsive sidebar changes the header's available width after ResizeObserver delivery. + await expect.poll(() => frame.getAttribute('data-sidebar-collapsed')).toBe(width < 1024 ? 'true' : null) const measure = () => header.evaluate((element) => { const heading = element.firstElementChild! const actions = element.lastElementChild! From 5d84c56d84ad5d146113c3bb974fc96e3b24070e Mon Sep 17 00:00:00 2001 From: fz Date: Tue, 13 Oct 2026 10:23:43 +0800 Subject: [PATCH 4/4] refactor(web): share font shortcut bindings and order actions --- .../shortcuts-desktop/font-sizes.expected.md | 6 +++++- apps/web/tests/shortcuts-desktop.e2e.ts | 9 +++++++-- packages/client/ui-shortcuts/README.i18n.yaml | 4 ++-- packages/client/ui-shortcuts/README.md | 2 +- packages/client/ui-shortcuts/README.zh.md | 2 +- .../ui-shortcuts/src/client/Reference.tsx | 2 ++ .../tests/reference.client.spec.tsx | 9 ++++++--- packages/client/ui-theme/README.i18n.yaml | 4 ++-- packages/client/ui-theme/README.md | 2 +- packages/client/ui-theme/README.zh.md | 2 +- packages/client/ui-theme/src/client/index.ts | 17 ++++++++++++----- 11 files changed, 40 insertions(+), 19 deletions(-) diff --git a/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md b/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md index 3ab8133eda..a4afd069e8 100644 --- a/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md +++ b/apps/web/tests/expected/shortcuts-desktop/font-sizes.expected.md @@ -30,5 +30,9 @@ "text": 14, "code": 11, "terminal": 13 - } + }, + "referenceOrder": [ + "Increase font size", + "Decrease font size" + ] } diff --git a/apps/web/tests/shortcuts-desktop.e2e.ts b/apps/web/tests/shortcuts-desktop.e2e.ts index d70b492133..7560831694 100644 --- a/apps/web/tests/shortcuts-desktop.e2e.ts +++ b/apps/web/tests/shortcuts-desktop.e2e.ts @@ -183,8 +183,7 @@ it.each([ const afterReload = await readFontSizes() await composer.focus() await stepFontSizes(`${primary}+Minus`, defaults) - await compareOrRefreshGolden(join(expected, 'font-sizes.expected.md'), - `# Font sizes\n\n${JSON.stringify({ initial, afterEqual, afterPlus, afterMinus, afterReload, restored: await readFontSizes() }, null, 2)}`, mode) + const restored = await readFontSizes() const dialog = page.getByRole('dialog', { name: 'Keyboard shortcuts', exact: true }) const settings = page.getByRole('dialog', { name: 'Settings', exact: true }) const automaticFocusStyle = () => page.evaluate(() => { @@ -241,6 +240,12 @@ it.each([ expect(await dialog.isVisible()).toBe(false) await openReference() await dialog.waitFor() + const referenceOrder = await dialog.getByRole('listitem').evaluateAll(rows => rows + .map(row => row.querySelector(':scope > span')?.textContent) + .filter(label => label === 'Increase font size' || label === 'Decrease font size')) + expect(referenceOrder).toEqual(['Increase font size', 'Decrease font size']) + await compareOrRefreshGolden(join(expected, 'font-sizes.expected.md'), + `# Font sizes\n\n${JSON.stringify({ initial, afterEqual, afterPlus, afterMinus, afterReload, restored, referenceOrder }, null, 2)}`, mode) expect(await dialog.getByRole('searchbox').evaluate(node => node === document.activeElement)).toBe(true) expect(await automaticFocusStyle()).toEqual(noFocusRing) const referenceShadow = await dialog.evaluate(node => getComputedStyle(node).boxShadow) diff --git a/packages/client/ui-shortcuts/README.i18n.yaml b/packages/client/ui-shortcuts/README.i18n.yaml index c19532d5f5..48f267d1ad 100644 --- a/packages/client/ui-shortcuts/README.i18n.yaml +++ b/packages/client/ui-shortcuts/README.i18n.yaml @@ -15,8 +15,8 @@ en: d152484eb41ac6b4 zh: 0cd57b7b8d8c9b59 /deepseek-ai-dsh-client-ui-shortcuts/use-this-package: - en: 045d38d5efdf1ff0 - zh: 86a700339f5abc49 + en: 84a109505e902f0a + zh: 87053c34cf4da672 /deepseek-ai-dsh-client-ui-shortcuts/understand-the-implementation: en: f56f2610e7258825 zh: 249d7cdd55c57166 diff --git a/packages/client/ui-shortcuts/README.md b/packages/client/ui-shortcuts/README.md index 8c874fb2bc..d6bf0cf06b 100644 --- a/packages/client/ui-shortcuts/README.md +++ b/packages/client/ui-shortcuts/README.md @@ -29,7 +29,7 @@ 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. -Core actions follow a fixed product order, independent of plugin registration, unloading, or remounting. Stopping the current response ends the Message input group and remains read-only. Extension commands outside that order follow the core actions in stable command ID order; other fixed actions retain their groups. +Core actions follow a fixed product order, independent of plugin registration, unloading, or remounting. Desktop's font-size actions follow Open settings, with Increase before Decrease. Stopping the current response ends the Message input group 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. Both platforms show each editable row’s complete key combination in one settings-control grey block with secondary ink. Fixed actions use unboxed tertiary text, cannot enter recording, and do not highlight on hover. Group titles align with command labels. diff --git a/packages/client/ui-shortcuts/README.zh.md b/packages/client/ui-shortcuts/README.zh.md index 4ba2688c9f..a8f61d7466 100644 --- a/packages/client/ui-shortcuts/README.zh.md +++ b/packages/client/ui-shortcuts/README.zh.md @@ -29,7 +29,7 @@ Web 应用 bundle 将此包与 `shortcuts` 一同挂载。速查仅展示已注 没有模态弹窗或设置位于最前方时,`Mod+/` 打开速查;速查位于最前方时,该快捷键关闭速查。速查位于前方时,设置命令不能打开或关闭设置。长按产生的重复按键不执行操作。录键期间、写入尚未完成或嵌套确认框打开时,速查快捷键不会关闭弹窗。 -核心操作采用固定产品顺序,不受插件注册、卸载或重新挂载影响。停止当前回复位于“消息输入”分组末尾,仍为只读项。未列入该顺序的扩展命令在核心操作之后按命令 ID 稳定排列;其余固定操作保留原有分组。 +核心操作采用固定产品顺序,不受插件注册、卸载或重新挂载影响。Desktop 的字号操作位于“打开设置”之后,“增大字号”在“减小字号”之前。停止当前回复位于“消息输入”分组末尾,仍为只读项。未列入该顺序的扩展命令在核心操作之后按命令 ID 稳定排列;其余固定操作保留原有分组。 搜索在单个操作名称、英文别名或按键组合内按字符顺序模糊匹配,忽略大小写。每个命中命令只出现一次。搜索时优先按相关性排序,同分项保留展示顺序。正常显示和录制时,应用操作行和固定操作行均保持 42 CSS 像素高;过长的命令名称会被截断。应用命令行只显示名称和改键控件,不显示可用性副标题或原因悬浮提示,冲突和无效绑定也不例外。无法执行的命令静默结束。两个平台均将可编辑行的完整快捷键放在同一个设置控件灰色色块中,使用次级文字色。固定操作使用无背景的三级文字色,不能进入录键,悬停时不高亮。分组标题与命令名称左对齐。 diff --git a/packages/client/ui-shortcuts/src/client/Reference.tsx b/packages/client/ui-shortcuts/src/client/Reference.tsx index d5dd35efd6..1235b27631 100644 --- a/packages/client/ui-shortcuts/src/client/Reference.tsx +++ b/packages/client/ui-shortcuts/src/client/Reference.tsx @@ -33,6 +33,8 @@ const coreActionOrder = new Map([ 'session.fork', 'session.archive', 'settings.open', + 'fontSize.increase', + 'fontSize.decrease', 'workspace.openLocal', 'sidebar.right.toggle', 'workspace.files', diff --git a/packages/client/ui-shortcuts/tests/reference.client.spec.tsx b/packages/client/ui-shortcuts/tests/reference.client.spec.tsx index d2ffd27699..2e79e2fb88 100644 --- a/packages/client/ui-shortcuts/tests/reference.client.spec.tsx +++ b/packages/client/ui-shortcuts/tests/reference.client.spec.tsx @@ -173,7 +173,7 @@ function referenceFixture({ runtime = 'web', dictionary = en }: { runtime?: 'web } it('keeps core actions in product order across registration, remount and label changes', () => { - const { catalog, fixedCatalog, store } = referenceFixture() + const { catalog, fixedCatalog, store } = referenceFixture({ runtime: 'desktop' }) const template = catalog.getSnapshot()[0]! const core = [ ['shortcuts.open', 'Keyboard shortcuts'], ['session.new', 'New session'], @@ -197,11 +197,14 @@ it('keeps core actions in product order across registration, remount and label c { ...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, id: 'fontSize.increase' as ShortcutCommandId, label: 'Increase font size', keys: ['⌘', '='], bindings: [{ code: 'Equal', modifiers: ['meta'] }], group: 'application' }, + { ...stop, id: 'fontSize.decrease' as ShortcutCommandId, label: 'Decrease font size', keys: ['⌘', '-'], bindings: [{ code: 'Minus', modifiers: ['meta'] }], group: 'application' }, stop, ] const labels = (group: string) => within(screen.getByRole('region', { name: group })).getAllByRole('listitem') .map(row => row.querySelector(':scope > span')?.textContent) - const expected = [...core.map(([, label]) => label), 'Zulu extension', 'Alpha extension'] + const expected = [...core.flatMap(([id, label]) => id === 'settings.open' + ? [label, 'Increase font size', 'Decrease font size'] : [label]), 'Zulu extension', 'Alpha extension'] for (const reversed of [true, false]) { act(() => { catalog.set(reversed ? [...extensions, ...commands].reverse() : [...extensions, ...commands]) @@ -218,7 +221,7 @@ it('keeps core actions in product order across registration, remount and label c 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']) + expect(labels(en.application)).toEqual(['Increase font size', 'Decrease font size', 'Zulu extension', 'Alpha extension']) act(() => { catalog.set([...extensions, ...[...commands].reverse()]); fixedCatalog.set(fixed) }) expect(labels(en.application)).toEqual(expected) act(() => { diff --git a/packages/client/ui-theme/README.i18n.yaml b/packages/client/ui-theme/README.i18n.yaml index 18476789c5..b208594041 100644 --- a/packages/client/ui-theme/README.i18n.yaml +++ b/packages/client/ui-theme/README.i18n.yaml @@ -18,8 +18,8 @@ en: 5a279269e31713c1 zh: dcd5c31fbdfd63e2 /deepseek-ai-dsh-client-ui-theme/use-this-package/appearance-and-font-size: - en: ce7888c9f8ca8b9a - zh: 829e0ce1a6cb8ac6 + en: cbfc02f8b3b02e0d + zh: 5a8f4d9d688d113c /deepseek-ai-dsh-client-ui-theme/use-this-package/fonts: en: b45d5b48ca799c3a zh: af65514b3759204f diff --git a/packages/client/ui-theme/README.md b/packages/client/ui-theme/README.md index 8c0e05825b..8904a359b2 100644 --- a/packages/client/ui-theme/README.md +++ b/packages/client/ui-theme/README.md @@ -31,7 +31,7 @@ Users switch the color scheme, font sizes, and fonts from rows in Settings (Gene The plugin registers Appearance preference cubes and the text font-size stepper in the General section. A More font settings button after the stepper expands a region below it, collapsed on every settings open, with a font row for each of text, code, and the terminal, plus the code and terminal font-size steppers. The text stepper accepts integer values from 10 through 22 px and defaults to 14 px. It changes conversation headings and base text by the same increment, including the user bubble and composer draft; flow-row titles, summaries, and tables follow one step under the body size, while small text keeps a fixed size. The code stepper (10–16 px, default 11) sets the code-block size; inline code stays 1 px larger, and the small tool-output variant uses the same size. The terminal stepper (10–20 px, default 13) sets the sidebar terminal cell font size; changing it keeps the shell and output and refits the grid. Each accepted change writes through the Host settings API. Rapid changes serialize in gesture order with namespace revisions, and a rejected latest write reloads the durable values. -Desktop's fixed `Cmd`/`Ctrl` + `+` (or `=`) and `Cmd`/`Ctrl` + `-` shortcuts change the text, code, and terminal font sizes together by 1 px, each within its own range. Each physical key press saves the changed fields in one settings mutation. The actions appear in the shortcut reference and work in the main document, including dialogs and text inputs, unless a local control consumes the input; terminal input retains its own key handling. Web retains the browser's zoom shortcuts. +Desktop's fixed `Cmd`/`Ctrl` + `+` (or `=`) and `Cmd`/`Ctrl` + `-` shortcuts change the text, code, and terminal font sizes together by 1 px, each within its own range. Each physical key press saves the changed fields in one settings mutation; holding a key does not repeat the adjustment. The actions appear in the shortcut reference and work in the main document, including dialogs and text inputs, unless a local control consumes the input; terminal input retains its own key handling. Web retains the browser's zoom shortcuts. ### Fonts diff --git a/packages/client/ui-theme/README.zh.md b/packages/client/ui-theme/README.zh.md index add05ecc38..a6c660c0db 100644 --- a/packages/client/ui-theme/README.zh.md +++ b/packages/client/ui-theme/README.zh.md @@ -31,7 +31,7 @@ kind: "package-reference" 插件在「通用」分区注册外观偏好方块与正文字号步进器。步进器后的「更多字体设置」按钮在其下方展开一个区域,每次打开设置时均为折叠状态,其中包含正文、代码与终端各自的字体行,以及代码与终端的字号步进器。正文步进器接受 10 至 22 px 的整数,默认值为 14 px。它以相同增量调整会话标题与基础文本,包括用户气泡与 composer 草稿;流内行的标题、摘要与表格跟随比正文低一档的字号,小号文本保持固定字号。代码步进器(10–16 px,默认 11)设置代码块字号;行内代码保持大 1 px,工具输出的小号变体使用相同字号。终端步进器(10–20 px,默认 13)设置侧栏终端的单元格字号;修改后保留 shell 与输出,并重新适配网格。每次通过的变更都经 Host settings API 写入。连续快速变更按操作顺序携带命名空间 revision 串行写入,最新写入被拒时重新加载持久值。 -Desktop 的固定快捷键 `Cmd`/`Ctrl` + `+`(或 `=`)和 `Cmd`/`Ctrl` + `-` 同时将正文、代码与终端字号增减 1 px,各自沿用其取值范围。每次实际按下按键,通过一次设置操作保存变化字段。这些操作显示在快捷键参考中,可在主文档的对话框和文本输入框内使用,但会让已消费输入的本地控件先处理;终端输入保留自身的按键处理。Web 保留浏览器的缩放快捷键。 +Desktop 的固定快捷键 `Cmd`/`Ctrl` + `+`(或 `=`)和 `Cmd`/`Ctrl` + `-` 同时将正文、代码与终端字号增减 1 px,各自沿用其取值范围。每次实际按下按键,通过一次设置操作保存变化字段;长按不会连续调整字号。这些操作显示在快捷键参考中,可在主文档的对话框和文本输入框内使用,但会让已消费输入的本地控件先处理;终端输入保留自身的按键处理。Web 保留浏览器的缩放快捷键。 ### 字体 diff --git a/packages/client/ui-theme/src/client/index.ts b/packages/client/ui-theme/src/client/index.ts index 9db94a50e3..f37bb34f4b 100644 --- a/packages/client/ui-theme/src/client/index.ts +++ b/packages/client/ui-theme/src/client/index.ts @@ -11,6 +11,7 @@ import type { Context as ClientContext } from '@deepseek-ai/cordis' import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots' import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client' +import type { NormalizedBinding } from '@deepseek-ai/dsh-client-shortcuts/protocol' // Type-only: the ctx.configForms Context merge. Cross-plugin collaboration // goes through the service, never a value import (client bundle purity gate). import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client' @@ -499,10 +500,15 @@ function installFontSizeShortcuts(ctx: ClientContext, adjust: (delta: 1 | -1) => ctx.inject(['shortcuts', 'locale'], (scope) => { if (scope.shortcuts.runtime !== 'desktop') return const t = scope.locale.bind(SETTINGS_NS) - for (const [direction, code] of [['increase', 'Equal'], ['decrease', 'Minus']] as const) { + const combinations: { binding: NormalizedBinding; delta: 1 | -1 }[] = [] + // Fixed bindings drive both reservation and matching. + for (const [direction, code, delta] of [['increase', 'Equal', 1], ['decrease', 'Minus', -1]] as const) { const binding = { code, modifiers: ['primary'] as const } const bindings = direction === 'increase' ? [binding, { code, modifiers: ['primary', 'shift'] as const }] as const : [binding] as const + for (const candidate of bindings) { + combinations.push({ binding: scope.shortcuts.describeBinding(candidate).binding as NormalizedBinding, delta }) + } scope.effect(() => scope.shortcuts.registerFixed({ id: `fontSize.${direction}` as ShortcutCommandId, label: () => t(`fontSize.text.${direction}`), keys: scope.shortcuts.describeBinding(binding).keys, @@ -512,11 +518,12 @@ function installFontSizeShortcuts(ctx: ClientContext, adjust: (delta: 1 | -1) => scope.effect(() => scope.shortcuts.observeFixedInput((input) => { if (input.type === 'reset') return const { gesture, context } = input - if (gesture.composing || gesture.defaultPrevented || gesture.repeat || context.region === 'terminal' - || gesture.alt || (scope.shortcuts.platform === 'macos' ? !gesture.meta || gesture.control : !gesture.control || gesture.meta) - || (gesture.code !== 'Equal' && gesture.code !== 'Minus') || (gesture.code === 'Minus' && gesture.shift)) return + if (gesture.composing || gesture.defaultPrevented || gesture.repeat || context.region === 'terminal') return + const matched = combinations.find(({ binding }) => binding.code === gesture.code + && (['control', 'alt', 'shift', 'meta'] as const).every(modifier => gesture[modifier] === binding.modifiers.includes(modifier))) + if (matched === undefined) return input.consume() - adjust(gesture.code === 'Equal' ? 1 : -1) + adjust(matched.delta) }), 'ui-theme: font size input') }) }