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): 搜索结果拦右键并在换词时滚回顶部

Dash21d56b4973fd
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
index 60a56be2e4..e7d3a3ab12 100644
--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
@@ -90,6 +90,8 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不
expect(topNavSource).toContain('if (section === \'scrollable\')');
expect(sidebarUpperSource).toContain('searchScrollRestoreRef.current = el.scrollTop');
expect(sidebarUpperSource).toContain("el.scrollTo({ top: searchScrollRestoreRef.current })");
+ expect(sidebarUpperSource).toContain('[searchActive, search.trimmed]');
+ expect(sidebarUpperSource).toContain('onContextMenu={(event) => event.stopPropagation()}');
expect(sidebarUpperSource).toContain('{searchActive ? (');
expect(sidebarUpperSource).toContain('<div hidden={searchActive}>');
expect(sidebarUpperSource).not.toContain('absolute inset-0 z-20');
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index 694f5cab1a..071041184a 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -1715,19 +1715,23 @@ function ExpandedView({
};
}, []);
// 搜索结果替换同一滚动容器里的列表:打开查询时记下原 scrollTop 再滚回顶部,
- // 清查询时还原,避免从结果中间开始看,也不把用户送回列表顶。
+ // 换关键词也滚回顶部;清查询时还原,避免从结果中间开始看,也不把用户送回列表顶。
const searchActive = Boolean(search.trimmed);
const searchScrollRestoreRef = useRef(0);
+ const wasSearchActiveRef = useRef(false);
useLayoutEffect(() => {
const el = sidebarScrollRef.current;
if (!el) return;
if (searchActive) {
- searchScrollRestoreRef.current = el.scrollTop;
+ if (!wasSearchActiveRef.current) {
+ searchScrollRestoreRef.current = el.scrollTop;
+ }
el.scrollTo({ top: 0 });
- return;
+ } else if (wasSearchActiveRef.current) {
+ el.scrollTo({ top: searchScrollRestoreRef.current });
}
- el.scrollTo({ top: searchScrollRestoreRef.current });
- }, [searchActive]);
+ wasSearchActiveRef.current = searchActive;
+ }, [searchActive, search.trimmed]);
// 含远程会话:device-link 远程行也渲染在可选行里,bulk 选择/归档/删除必须能解析到它们
// (否则选中远程行 → 计数加了但 archive/delete 查 sessionsById 落空、静默忽略)。
const sessionsById = useMemo(
@@ -3109,7 +3113,10 @@ function ExpandedView({
只钉搜索行,输入框保持同一份实例,结果替换下方列表。 */}
<SidebarTopNav section="scrollable" />
{searchActive ? (
- <div data-conversation-search-surface>
+ <div
+ data-conversation-search-surface
+ onContextMenu={(event) => event.stopPropagation()}
+ >
<SearchResultsBody
trimmed={search.trimmed}
status={search.status}