Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(workdir-browse): 横向扩展占位不参与行布局,短名跳转不再被滚出视口

Zhang Yunjin59f3cf08c251
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.tsx
index 310938e57a..302c668d0f 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
@@ -397,24 +397,26 @@ export const FileTreeView = forwardRef<FileTreeViewHandle, FileTreeViewProps>(fu
// 横向范围的粘性下限:虚拟化只挂视口内的行,横向范围完全由当前挂载行撑出 ——
// 用户向右滚到深层长名后再纵向滚开,宽行被回收、横向范围缩小,浏览器会把
// scrollLeft 拉回(评审:纵向滚动拉回横向位置)。记录本树已测得的最大内容宽,
- // 作为内容层的单调不减 minWidth;换树(storeKey 变)时重置。jsdom 无布局
- // (scrollWidth 恒 0),直接操作 DOM 不额外渲染。#4436 的行宽契约不变:
- // 行仍 min-w-max,这里只是不让「测得过的最大宽」随回收缩水。
- const contentLayerRef = useRef<HTMLDivElement | null>(null);
- const stickyMinWidthRef = useRef(0);
+ // 用一个绝对定位的扩展占位元素撑住滚动范围 —— 占位不参与行布局,行宽
+ // (width:100%)不会被撑宽,alignRowHorizontally 的行右缘对齐保持原语义
+ // (评审:粘性 minWidth 会把短名滚出视口)。换树(storeKey 变)时重置。
+ // jsdom 无布局(scrollWidth 恒 0)时测得 0,不渲染占位。
+ const [stickyExtentWidth, setStickyExtentWidth] = useState(0);
+ const stickyExtentRef = useRef(0);
const stickyStoreKeyRef = useRef(tree.storeKey);
+ const contentLayerRef = useRef<HTMLDivElement | null>(null);
useLayoutEffect(() => {
- const inner = contentLayerRef.current;
- if (!inner) return;
if (stickyStoreKeyRef.current !== tree.storeKey) {
stickyStoreKeyRef.current = tree.storeKey;
- stickyMinWidthRef.current = 0;
- inner.style.minWidth = '';
+ stickyExtentRef.current = 0;
+ setStickyExtentWidth(0);
}
+ const inner = contentLayerRef.current;
+ if (!inner) return;
const measured = inner.scrollWidth;
- if (measured > stickyMinWidthRef.current) {
- stickyMinWidthRef.current = measured;
- inner.style.minWidth = `${measured}px`;
+ if (measured > stickyExtentRef.current) {
+ stickyExtentRef.current = measured;
+ setStickyExtentWidth(measured);
}
}, [rows, tree.storeKey]);
@@ -631,6 +633,14 @@ export const FileTreeView = forwardRef<FileTreeViewHandle, FileTreeViewProps>(fu
emptyState
) : (
<div ref={contentLayerRef} className="relative w-full" style={{ height: virtualizer.getTotalSize() }}>
+ {stickyExtentWidth > 0 && (
+ <div
+ aria-hidden
+ data-testid="tree-horizontal-extent"
+ className="pointer-events-none absolute left-0 top-0 h-px"
+ style={{ width: stickyExtentWidth }}
+ />
+ )}
{virtualizer.getVirtualItems().map((vi) => {
const row = rows[vi.index];
if (!row) return null;
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.tsx
index d605dfa84a..4c0abb6111 100644
--- 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.tsx
@@ -327,36 +327,37 @@ describe('globals.css 里的 .tree-hscroll 规则', () => {
/**
* 评审(纵向滚动拉回横向位置):虚拟化只挂视口内的行,横向范围完全由当前
- * 挂载行撑出 —— 宽行被回收时范围缩小,浏览器会把 scrollLeft 拉回。内容层
- * 要保留本树已测得的最大宽(单调不减 minWidth),换树时才重置。
+ * 挂载行撑出 —— 宽行被回收时范围缩小,浏览器会把 scrollLeft 拉回。用绝对定位
+ * 的扩展占位保留本树已测得的最大宽(不参与行布局,行宽不被撑宽),换树重置。
*/
- it('回收宽行不缩小横向范围:内容层保留已测得的最大宽,换树才重置', () => {
+ it('回收宽行不缩小横向范围:扩展占位保留已测得的最大宽,换树才重置', () => {
const { container, rerender } = render(
<FileTreeView tree={makeTree()} scrollScope="tab-1" selectedPath={null} onSelectFile={vi.fn()} />,
);
const inner = container.querySelector<HTMLElement>('div.relative.w-full')!;
Object.defineProperty(inner, 'scrollWidth', { configurable: true, value: 500 });
- // 宽行挂载时测得 500:写入粘性 minWidth。
+ // 宽行挂载时测得 500:占位把横向范围撑到 500。
rerender(
<FileTreeView tree={makeTree()} scrollScope="tab-1" selectedPath={null} onSelectFile={vi.fn()} />,
);
- expect(inner.style.minWidth).toBe('500px');
+ const spacer = container.querySelector<HTMLElement>('[data-testid="tree-horizontal-extent"]')!;
+ expect(spacer).not.toBeNull();
+ expect(spacer.style.width).toBe('500px');
- // 宽行被回收(后续测得更窄):粘性 minWidth 不缩,横向滚动范围不变小。
+ // 宽行被回收(后续测得更窄):占位不缩,横向滚动范围不变小。
Object.defineProperty(inner, 'scrollWidth', { configurable: true, value: 200 });
rerender(
<FileTreeView tree={makeTree()} scrollScope="tab-1" selectedPath={null} onSelectFile={vi.fn()} />,
);
- expect(inner.style.minWidth).toBe('500px');
+ expect(spacer.style.width).toBe('500px');
- // 换树(storeKey 变):粘性宽重置,等新树自己重新测量(先撤掉 stub,让
- // jsdom 回到真实 scrollWidth=0,验证重置本身)。
+ // 换树(storeKey 变):占位移除,等新树自己重新测量(先撤 stub 验证重置本身)。
Reflect.deleteProperty(inner, 'scrollWidth');
const switchedTree = { ...makeFarTargetsTree(), storeKey: 'test-store-2', treeIdentityKey: 'test-store-2' };
rerender(
<FileTreeView tree={switchedTree} scrollScope="tab-1" selectedPath={null} onSelectFile={vi.fn()} />,
);
- expect(inner.style.minWidth).toBe('');
+ expect(container.querySelector('[data-testid="tree-horizontal-extent"]')).toBeNull();
});
});