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(sidebar): 搜索包装层保留间距并冻住程序化打开时的列表位置

Dash879a7ce36c09
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
index 01922a2ded..efc22abf43 100644
--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
@@ -94,7 +94,10 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不
expect(sidebarUpperSource).toContain('searchProjectKey');
expect(sidebarUpperSource).toContain('onContextMenu={(event) => event.stopPropagation()}');
expect(sidebarUpperSource).toContain('{searchActive ? (');
- expect(sidebarUpperSource).toContain('<div hidden={searchActive}>');
+ expect(sidebarUpperSource).toContain('<div hidden={searchActive} className="flex flex-col gap-2">');
+ expect(sidebarUpperSource).toContain('freezeListScrollOnOpenRef.current = true');
+ const inlineSearchSource = read('features', 'cc-agent', 'sidebar', 'SidebarInlineSearch.tsx');
+ expect(inlineSearchSource).toContain('inputRef.current?.focus({ preventScroll: true })');
expect(sidebarUpperSource).not.toContain('absolute inset-0 z-20');
expect(sidebarUpperSource).not.toContain(
"search.trimmed && 'sticky top-0 z-30 bg-[var(--cmd-palette-bg)]'",
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index 17a302f32e..9f4e44998d 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -1348,7 +1348,7 @@ function ExpandedView({
// 内联会话搜索:输入行在 SidebarTopNav 的第 4 行,状态经 ConversationSearchProvider 共享;
// query 非空时同一份顶部导航 sticky 钉住,结果替换下方列表,不再用 overlay 盖输入框。
- const { search } = useConversationSearchContext();
+ const { search, openSignal } = useConversationSearchContext();
const gcProjectKeys = useMemo(
() => projectUniverse.projects.map((p) => p.projectKey),
[projectUniverse.projects],
@@ -1703,11 +1703,21 @@ function ExpandedView({
// 搜索激活前持续记下列表 scrollTop:layout effect 跑时原列表已经 hidden,
// 那时再读会被浏览器钳成 0。
const lastListScrollTopRef = useRef(0);
+ // 「在此项目内搜索」会在 query 仍空时 focus 输入框,浏览器先把搜索行滚进视野。
+ // 这段窗口里 searchActive 仍是 false,滚动监听会把焦点滚动后的偏移当成列表位置。
+ const freezeListScrollOnOpenRef = useRef(false);
+ const lastOpenSignalRef = useRef(openSignal);
+ if (openSignal !== lastOpenSignalRef.current) {
+ lastOpenSignalRef.current = openSignal;
+ if (openSignal > 0 && !searchActive) {
+ freezeListScrollOnOpenRef.current = true;
+ }
+ }
useEffect(() => {
const el = sidebarScrollRef.current;
if (!el) return undefined;
const update = () => {
- if (!searchActiveRef.current) {
+ if (!searchActiveRef.current && !freezeListScrollOnOpenRef.current) {
lastListScrollTopRef.current = el.scrollTop;
}
const next = el.scrollTop > 1;
@@ -1732,8 +1742,10 @@ function ExpandedView({
const el = sidebarScrollRef.current;
if (!el) return;
if (searchActive) {
+ freezeListScrollOnOpenRef.current = false;
el.scrollTo({ top: 0 });
} else if (wasSearchActiveRef.current) {
+ freezeListScrollOnOpenRef.current = false;
el.scrollTo({ top: lastListScrollTopRef.current });
}
wasSearchActiveRef.current = searchActive;
@@ -3140,7 +3152,7 @@ function ExpandedView({
</div>
) : null}
{/* 搜索时原列表只隐藏、不卸载:置顶段折叠等本地 state 才能保住。 */}
- <div hidden={searchActive}>
+ <div hidden={searchActive} className="flex flex-col gap-2">
{remoteDeviceDirectoryStatus === 'error' && !hasVisibleSidebarContent ? (
<>
<MainListScopeHeader
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx
index 70c6c18d5e..528d41bcff 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarInlineSearch.tsx
@@ -79,7 +79,7 @@ export function SidebarInlineSearch({
useEffect(() => {
if (!openSignal) return;
setForceOpen(true);
- const id = window.setTimeout(() => inputRef.current?.focus(), 0);
+ const id = window.setTimeout(() => inputRef.current?.focus({ preventScroll: true }), 0);
return () => window.clearTimeout(id);
}, [openSignal]);