Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 文件树行宽随内容展开并补常显横向滚动条 (#4436)
Yunjin Zhangdf8ff6d2bef0
diff --git a/apps/desktop/src/renderer/features/cc-agent/workdir-browse/FileTreeView.tsx b/apps/desktop/src/renderer/features/cc-agent/workdir-browse/FileTreeView.tsxindex 57837c4b6a..9c3b1a18da 100644--- a/apps/desktop/src/renderer/features/cc-agent/workdir-browse/FileTreeView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/workdir-browse/FileTreeView.tsx@@ -309,7 +309,13 @@ export const FileTreeView = forwardRef<FileTreeViewHandle, FileTreeViewProps>(fuconst isFolderMenu = menu?.entry.type === 'directory';return (- <div ref={containerRef} className="flex h-full w-full flex-col gap-px overflow-y-auto py-2">+ // 横向溢出契约:行宽由内容决定(行 min-w-max:深层缩进 + 完整文件名/输入框),+ // 容器显式 overflow-auto 承接横向滚动;tree-hscroll 让横条常显(见 globals.css)——+ // 横向溢出没有"被截断"的视觉线索,thumb 默认透明时会被当成"没有滚动条"。+ <div+ ref={containerRef}+ className="tree-hscroll flex h-full w-full flex-col gap-px overflow-auto py-2"+ >{rows.map((row) => {if (row.kind === 'pending') {return (@@ -623,7 +629,9 @@ function FileTreeRow({// 未来要"展开到某个文件夹"也能直接复用。data-relpath={entry.relPath}className={cn(- 'group/file-row flex h-7 w-full shrink-0 items-center rounded-md pr-2',+ // min-w-max:行宽由内容决定(缩进 + 完整名字),深层级/长名字撑出横向滚动区,+ // 而不是把名字 truncate 到 0 宽;内容比容器窄时 w-full 仍撑满整行。+ 'group/file-row flex h-7 w-full min-w-max shrink-0 items-center rounded-md pr-2','cursor-pointer text-13 transition-colors',selected? 'bg-sidebar-item-active font-medium text-sidebar-item-active-foreground'@@ -786,7 +794,8 @@ function RenamingInputRow({ entry, depth, onSubmit, onCancel }: RenamingInputRow<divstyle={{ paddingLeft }}className={cn(- 'flex h-7 w-full shrink-0 items-center gap-1.5 rounded-md pr-2',+ // 同 FileTreeRow:深层重命名输入框不能被缩进挤没,行宽跟随输入框自身宽度。+ 'flex h-7 w-full min-w-max shrink-0 items-center gap-1.5 rounded-md pr-2','bg-sidebar-item-active text-sidebar-item-active-foreground',)}>@@ -856,7 +865,8 @@ function PendingInputRow({ pending, depth, onSubmit, onCancel }: PendingInputRow<divstyle={{ paddingLeft }}className={cn(- 'flex h-7 w-full shrink-0 items-center gap-1.5 rounded-md pr-2',+ // 同 FileTreeRow:深层的新建输入框不能被缩进挤没,行宽由输入框自身宽度决定。+ 'flex h-7 w-full min-w-max shrink-0 items-center gap-1.5 rounded-md pr-2','bg-sidebar-item-active text-sidebar-item-active-foreground',)}>diff --git a/apps/desktop/src/renderer/features/cc-agent/workdir-browse/__tests__/FileTreeView.horizontalScroll.test.tsx b/apps/desktop/src/renderer/features/cc-agent/workdir-browse/__tests__/FileTreeView.horizontalScroll.test.tsxnew file mode 100644index 0000000000..a78e714e63--- /dev/null+++ b/apps/desktop/src/renderer/features/cc-agent/workdir-browse/__tests__/FileTreeView.horizontalScroll.test.tsx@@ -0,0 +1,119 @@+// @vitest-environment jsdom++/**+ * FileTreeView 横向滚动契约(组件结构 + globals.css 规则两层)。+ *+ * jsdom 不做布局,这里锁的是「行宽由内容决定 + 容器承接横向滚动 + 横条常显」这组+ * 结构不变量;真实几何由实机 CDP 复测(2026-09-14,200px 面板 + 真实样式表):+ * 修复前行 depth ≥9 名字宽 0、scrollWidth 只有 280;修复后行宽跟随内容,depth 15+ * 名字恢复全宽、scrollWidth 549,横滚可读到全名。+ *+ * 背景:窄面板(RSB 文件浏览器 200px)里深层目录会一路缩进,旧行 `w-full` ++ * 名字 `truncate` 只会把内容挤成 0 宽,永远撑不出滚动区 —— 深层目标"消失"且没有+ * 横向滚动条可救。CSS 规则存在性靠静态断言(jsdom 不加载样式表),与+ * __tests__/diffHorizontalScroll.test.tsx 的既有做法一致。+ */++import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { cleanup, render, screen } from '@testing-library/react';+import { afterEach, describe, expect, it, vi } from 'vitest';++vi.mock('react-i18next', () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++import { FileTreeView } from '../FileTreeView';+import type { DirEntry, UseFileTreeReturn } from '../hooks/useFileTree';++const globalsSrc = readFileSync(+ resolve(__dirname, '..', '..', '..', '..', 'styles', 'globals.css'),+ 'utf8',+);++const rootEntries: DirEntry[] = [+ { name: 'cat.png', relPath: 'cat.png', type: 'file', size: 10, mtimeMs: 1 },+ { name: 'deep', relPath: 'deep', type: 'directory', size: 0, mtimeMs: 2 },+];+const deepEntries: DirEntry[] = [+ { name: 'l2', relPath: 'deep/l2', type: 'directory', size: 0, mtimeMs: 3 },+];+const deeperEntries: DirEntry[] = [+ { name: 'l3', relPath: 'deep/l2/l3', type: 'directory', size: 0, mtimeMs: 4 },+];++function makeTree(): UseFileTreeReturn {+ return {+ entries: new Map([+ ['', rootEntries],+ ['deep', deepEntries],+ ['deep/l2', deeperEntries],+ ]),+ expanded: new Set(['', 'deep', 'deep/l2']),+ loadingPaths: new Set(),+ initialLoading: false,+ loadError: null,+ toggleFolder: vi.fn(),+ collapseAll: vi.fn(),+ refresh: vi.fn(async () => undefined),+ expandToPath: vi.fn(async () => undefined),+ };+}++afterEach(() => cleanup());++describe('FileTreeView 横向滚动契约', () => {+ it('滚动容器承接横向溢出,并挂常显横条样式钩子(tree-hscroll)', () => {+ const { container } = render(+ <FileTreeView tree={makeTree()} selectedPath={null} onSelectFile={vi.fn()} />,+ );++ // 根节点即滚动容器(scrollToPath querySelector 也依赖它)。+ const scroll = container.firstElementChild as HTMLElement;+ expect(scroll.className).toContain('overflow-auto');+ expect(scroll.className).toContain('tree-hscroll');+ });++ it('文件行 / 重命名行 / 新建行都按内容撑宽(min-w-max),深层缩进不再挤没内容', () => {+ render(+ <FileTreeView+ tree={makeTree()}+ selectedPath={null}+ onSelectFile={vi.fn()}+ renamingPath="cat.png"+ onRenameSubmit={vi.fn()}+ onRenameCancel={vi.fn()}+ pendingCreate={{ kind: 'file', parentRel: '' }}+ onPendingSubmit={vi.fn()}+ onPendingCancel={vi.fn()}+ />,+ );++ // depth 2 的目录行(deep/l2/l3):未处于编辑态的文件/文件夹行。+ const deepRow = screen.getByText('l3').closest('[data-relpath]');+ expect(deepRow?.className).toContain('min-w-max');++ // 重命名行:input 的父节点就是行容器。+ const renameRow = screen.getByDisplayValue('cat.png').parentElement;+ expect(renameRow?.className).toContain('min-w-max');++ // 新建行:placeholder 由 pending.kind 决定,这里 file → untitled。+ const pendingRow = screen.getByPlaceholderText('untitled').parentElement;+ expect(pendingRow?.className).toContain('min-w-max');+ });+});++describe('globals.css 里的 .tree-hscroll 规则', () => {+ it('横向 thumb 用 --msg-scrollbar(不是透明)', () => {+ expect(globalsSrc).toMatch(+ /\.tree-hscroll::-webkit-scrollbar-thumb:horizontal\s*\{\s*background-color:\s*var\(--msg-scrollbar\);\s*\}/,+ );+ });++ it('横向槽厚 12px,与全局纵向槽宽对齐', () => {+ expect(globalsSrc).toMatch(+ /\.tree-hscroll::-webkit-scrollbar:horizontal\s*\{\s*height:\s*12px;\s*\}/,+ );+ expect(globalsSrc).toMatch(/::-webkit-scrollbar\s*\{\s*width:\s*12px;\s*\}/);+ });+});diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.cssindex 9caede20ea..5b194d1491 100644--- a/apps/desktop/src/renderer/styles/globals.css+++ b/apps/desktop/src/renderer/styles/globals.css@@ -1574,6 +1574,23 @@ body.resizing-pane [data-ghost-webview] {background-color: var(--msg-scrollbar-hover);}+/* workdir-browse FileTreeView 的横向滚动条 —— 常显,不参与 `.is-scrolling` 自动隐藏+ 体系。+ why:文件树行宽由内容决定(行 min-w-max:深层缩进 + 完整文件名/输入框),窄面板里+ 必须横滚才能看到深层目标;横向溢出没有“被截断”的视觉线索,thumb 默认透明时用户会认为+ 这里没有滚动条(2026-09-14 用户反馈「文件树缺少横向滚动条,层级过深看不见目标层级」)。+ 槽厚 12px 与全局纵向槽宽对齐,thumb 同样靠 3px 透明 border 收成可见 6px;+ `:horizontal` 让规则只吃横向条,纵向条继续走 auto-hide。 */+.tree-hscroll::-webkit-scrollbar:horizontal {+ height: 12px;+}+.tree-hscroll::-webkit-scrollbar-thumb:horizontal {+ background-color: var(--msg-scrollbar);+}+.tree-hscroll::-webkit-scrollbar-thumb:horizontal:hover {+ background-color: var(--msg-scrollbar-hover);+}+/* F-QUEUE-DEFER · PendingQueuePanel — slim 4px scrollbar so the`scrollbar-gutter: stable both-edges` reserved slot is small(4px each side instead of 12px). Without this, the chip-bg rows