Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 保持失焦文字选区清晰可见
Lizi69e6e26662a7
diff --git a/apps/desktop/src/renderer/__tests__/globalTextSelectionColor.test.ts b/apps/desktop/src/renderer/__tests__/globalTextSelectionColor.test.tsnew file mode 100644index 0000000000..0465cdf540--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/globalTextSelectionColor.test.ts@@ -0,0 +1,44 @@+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { describe, expect, it } from 'vitest';++import { colorRegistry } from '../themes/color-registry';+import '../themes/colors';+import { isProtectedToken } from '../../shared/theme-import/protected-tokens';++const globalsSource = readFileSync(resolve(__dirname, '..', 'styles', 'globals.css'), 'utf8');+const editorThemeSource = readFileSync(+ resolve(__dirname, '..', 'components', 'markdown', 'codemirrorGithubTheme.ts'),+ 'utf8',+);++/**+ * 宿主文字选中后把焦点移进插件 webview 时,Chromium 会把未样式化的原生选区+ * 改成很深的 inactive 色。这里锁住全局接线、编辑器一致性与双模式 token,+ * 防止选区仍在却再次看起来像被取消。+ */+describe('global text selection color', () => {+ it('uses the dedicated selection token for native host selections', () => {+ expect(globalsSource).toMatch(+ /::selection\s*\{\s*background:\s*var\(--text-selection-bg\);\s*\}/,+ );+ });++ it('defines the selection token for both themes from the stable focus blue', () => {+ expect(colorRegistry.resolveDefault('text-selection-bg', 'light')).toBe(+ 'var(--focus-ring-soft)',+ );+ expect(colorRegistry.resolveDefault('text-selection-bg', 'dark')).toBe(+ 'var(--focus-ring-soft)',+ );+ });++ it('keeps CodeMirror selections aligned with the native host selection', () => {+ expect(editorThemeSource).not.toContain("background: 'var(--focus-ring-soft)");+ expect(editorThemeSource.match(/background: 'var\(--text-selection-bg\)/g)).toHaveLength(6);+ });++ it('keeps imported themes from replacing the selection visibility color', () => {+ expect(isProtectedToken('text-selection-bg')).toBe(true);+ });+});diff --git a/apps/desktop/src/renderer/components/markdown/codemirrorGithubTheme.ts b/apps/desktop/src/renderer/components/markdown/codemirrorGithubTheme.tsindex 0c65505a53..a19917e714 100644--- a/apps/desktop/src/renderer/components/markdown/codemirrorGithubTheme.ts+++ b/apps/desktop/src/renderer/components/markdown/codemirrorGithubTheme.ts@@ -185,13 +185,13 @@ function makeEditorTheme(c: typeof githubLightColors, isDark: boolean) {fontFamily: CODE_FONT_STACK,lineHeight: '1.5',},- // Selection uses the shared focus ring alpha token so alternate themes can- // keep editor selection aligned with the rest of the app.+ // Selection uses the app-wide selection token so editor and document+ // selections remain identical when focus moves into an embedded webview.'.cm-selectionBackground, ::selection': {- background: 'var(--focus-ring-soft) !important',+ background: 'var(--text-selection-bg) !important',},'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground': {- background: 'var(--focus-ring-soft)',+ background: 'var(--text-selection-bg)',},// No active-line highlight (user disliked it earlier).'.cm-activeLine, .cm-activeLineGutter': { background: 'transparent' },@@ -281,10 +281,10 @@ function makePlainEditorTheme(isDark: boolean) {lineHeight: '1.6',},'.cm-selectionBackground, ::selection': {- background: 'var(--focus-ring-soft) !important',+ background: 'var(--text-selection-bg) !important',},'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground': {- background: 'var(--focus-ring-soft)',+ background: 'var(--text-selection-bg)',},'.cm-activeLine, .cm-activeLineGutter': { background: 'transparent' },'.cm-cursor, .cm-dropCursor': { borderLeftColor: text },@@ -670,10 +670,10 @@ function makeMarkdownEditorTheme(isDark: boolean) {wordBreak: 'break-word',},'.cm-selectionBackground, ::selection': {- background: 'var(--focus-ring-soft) !important',+ background: 'var(--text-selection-bg) !important',},'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground': {- background: 'var(--focus-ring-soft)',+ background: 'var(--text-selection-bg)',},'.cm-activeLine, .cm-activeLineGutter': { background: 'transparent' },'.cm-cursor, .cm-dropCursor': { borderLeftColor: text },diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.cssindex c275639924..b5404a83c7 100644--- a/apps/desktop/src/renderer/styles/globals.css+++ b/apps/desktop/src/renderer/styles/globals.css@@ -65,6 +65,12 @@user-select: text;}+ /* 原生选区默认会在宿主失去焦点后变成深色,看起来像选中被取消。+ 选中范围仍然存在,这里固定提示色,让用户切到插件/webview 后仍能看见。 */+ ::selection {+ background: var(--text-selection-bg);+ }+button,[role='button'],[role='menuitem'],diff --git a/apps/desktop/src/renderer/themes/colors.ts b/apps/desktop/src/renderer/themes/colors.tsindex a627b7ade5..45b48dcce3 100644--- a/apps/desktop/src/renderer/themes/colors.ts+++ b/apps/desktop/src/renderer/themes/colors.ts@@ -1954,6 +1954,10 @@ registerColor('focus-ring-soft', {light: 'rgba(65, 124, 221, 0.5)',dark: 'rgba(65, 124, 221, 0.5)',}, '50% alpha focus ring(随 focus-ring #417CDD,定稿 2026-07-17)— 替代 ring-[#xxx]/50 写法');+registerColor('text-selection-bg', {+ light: 'var(--focus-ring-soft)',+ dark: 'var(--focus-ring-soft)',+}, '文字选中背景(焦点离开宿主窗口时仍保持清晰可见)');registerColor('shadow-menu', {light: '0 4px 16px rgba(0, 0, 0, 0.15)',dark: '0 4px 16px rgba(0, 0, 0, 0.5)',diff --git a/apps/desktop/src/shared/theme-import/protected-tokens.ts b/apps/desktop/src/shared/theme-import/protected-tokens.tsindex 3f6891045f..ae4f22f3d1 100644--- a/apps/desktop/src/shared/theme-import/protected-tokens.ts+++ b/apps/desktop/src/shared/theme-import/protected-tokens.ts@@ -42,9 +42,10 @@ const PROTECTED_IDS = new Set<string>([// 权限语义色(自动审批蓝 / bypass 橙)'perm-auto-selected-text','perm-bypass-selected-text',- // 无障碍焦点环+ // 无障碍焦点环与文字选中提示色'focus-ring','focus-ring-soft',+ 'text-selection-bg',// 阴影:跨主题恒定,不是可换肤的风格项'shadow-menu','cmd-palette-shadow',diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex 02699e4385..0376d5f7cd 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -414,6 +414,7 @@ Theme switching: `useTheme.ts` provides `theme` (System / Light / Dark mode) plu| `--warning-bg-soft` | rgba(234,107,23,0.12) | rgba(234,107,23,0.18) | Warning alpha surface (alpha recomputed against `#EA6B17`, 2026-07-17) || `--warning-fg` | `#F3A115` | `#F3A115` | Warning text/icons, including the update-restart busy-turn interruption hint || `--focus-ring` / `--focus-ring-soft` | `#417CDD` / @50% | same | A11y focus ring, finalized 2026-07-17 (replaces #3b82f6), theme-invariant |+| `--text-selection-bg` | `var(--focus-ring-soft)` | same | Selected text background; remains visible when focus moves into an embedded webview || `--shadow-menu` / `--cmd-palette-shadow` / `--confirm-shadow` | rgba | rgba (deeper) | Shadows, theme-invariant || `--overlay-modal` / `--overlay-lightbox` | rgba | rgba (deeper) | Modal / lightbox backdrop || `--perm-auto-selected-text` | `#417CDD` | `#417CDD` | Auto Approval accent, finalized 2026-07-17 (same value both modes; replaces #000050/#00D9C5) |@@ -526,6 +527,7 @@ Known but deliberately-deferred cleanups (e.g. hardcoded hex in `MakerExperiment### 14.1 Text Selectability (user-select)- **Content is selectable**: message body text, code blocks, document previews — anything the user reads sentence-by-sentence or may want to copy. Selectable by default; leave it alone.+- **Selections survive focus changes**: moving focus into an embedded webview (plugin panel, built-in browser, etc.) must not clear the host selection or let Chromium repaint it as an unreadable inactive color. Global and editor selections use `--text-selection-bg`, which remains visible in both Light and Dark modes.- **Chrome is not selectable**: buttons, menu items, labels/chips, status bars, badges, toolbars, sidebar rows — interface-skeleton text gets `select-none`. They are controls, not content; being selectable only gets in the way (typical offender: the goal-status chip label).- Litmus test: would the user ever think "let me copy this"? Yes → selectable; no (it's just a control) → `select-none`.