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(desktop): 避免步骤胶囊与底部导航重叠 (#3319)

DavidShenXDf0c92ad90a8c
diff --git a/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts b/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts
index b1fc1ff090..a599bb62cf 100644
--- a/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts
+++ b/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts
@@ -109,6 +109,12 @@ describe('controlled banner placement', () => {
);
expect(todoListSource).toContain('data-plan-pill-anchor="true"');
expect(todoListSource).toContain('data-plan-flyout-positioner="composer"');
+ expect(sessionViewSource).toContain(
+ 'const mutationObserver = new MutationObserver(syncResizeTargetsAndMeasure);',
+ );
+ expect(sessionViewSource).toContain(
+ 'mutationObserver.observe(overlayEl, { childList: true, subtree: true });',
+ );
expect(sessionViewSource).not.toContain('fitContent=');
expect(pinnedPlanSource).not.toContain('fitContent');
expect(todoListSource).not.toContain('fitContent');
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index a5b44ff052..ccc2ea267c 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -375,8 +375,8 @@ interface MessageStreamProps {
historyWindowHasIsland?: boolean;
/** Dynamic bottom padding (px) to reserve space for the input overlay */
bottomPadding?: number;
- /** Distance from the chat viewport bottom to the visible composer stack top. */
- composerStackTopOffset?: number;
+ /** Distance from the chat viewport bottom to the topmost occupied bottom-center layer. */
+ bottomCenterClearanceOffset?: number;
/** Content width — shared with the input overlay so chat stream + input
* box stay horizontally aligned (same width, same center, symmetric
* padding when the main area is compressed). */
@@ -2957,7 +2957,7 @@ export function MessageStream({
hasMoreMessages,
historyWindowHasIsland = false,
bottomPadding,
- composerStackTopOffset,
+ bottomCenterClearanceOffset,
contentWidth,
getContentWidth,
focusMessageClientId,
@@ -5658,12 +5658,12 @@ export function MessageStream({
previousLocalFileRefsRef.current = localFileRefs;
}, [localFileRefs]);
- // chip 垂直位置:优先使用父层实测的输入框卡片顶边,避免 RunningStatusBar
- // 出现 / 收起改变 overlay 总高度后,把按钮带进输入框。旧调用方保留历史兜底。
+ // chip 垂直位置:优先使用父层实测的底部中央避让边界。普通状态行不占中央槽,
+ // 步骤 / 接管胶囊在场时则把按钮抬到它们上方;旧调用方保留历史兜底。
const resolvedBottomPadding = bottomPadding ?? 200;
const indicatorBottomOffset = resolveMessageStreamIndicatorBottomOffset({
bottomPadding,
- composerStackTopOffset,
+ bottomCenterClearanceOffset,
});
const latestInlinePlanRendered = Boolean(
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/messageStreamIndicatorPosition.test.ts b/apps/desktop/src/renderer/components/chat/__tests__/messageStreamIndicatorPosition.test.ts
index 1d4b9e943a..63a3796550 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/messageStreamIndicatorPosition.test.ts
+++ b/apps/desktop/src/renderer/components/chat/__tests__/messageStreamIndicatorPosition.test.ts
@@ -1,7 +1,8 @@
import { describe, expect, it, vi } from 'vitest';
import {
- measureComposerStackTopOffset,
+ getMessageStreamIndicatorResizeTargets,
+ measureMessageStreamIndicatorClearanceOffset,
resolveMessageStreamIndicatorBottomOffset,
} from '../messageStreamIndicatorPosition';
@@ -10,13 +11,13 @@ describe('resolveMessageStreamIndicatorBottomOffset', () => {
expect(
resolveMessageStreamIndicatorBottomOffset({
bottomPadding: 174,
- composerStackTopOffset: 142,
+ bottomCenterClearanceOffset: 142,
}),
).toBe(148);
expect(
resolveMessageStreamIndicatorBottomOffset({
bottomPadding: 206,
- composerStackTopOffset: 142,
+ bottomCenterClearanceOffset: 142,
}),
).toBe(148);
});
@@ -26,19 +27,110 @@ describe('resolveMessageStreamIndicatorBottomOffset', () => {
expect(resolveMessageStreamIndicatorBottomOffset({ bottomPadding: 40 })).toBe(12);
});
- it('measures from the outer composer stack so goal and plan indicators stay above the button', () => {
+ it('uses the composer stack when the center lane is empty', () => {
const composerStack = {
getBoundingClientRect: () => ({ top: 620 }),
} as HTMLElement;
- const querySelector = vi.fn((selector: string) =>
- selector === '[data-chat-composer-stack]' ? composerStack : null,
- );
+ const centerGroup = {
+ childElementCount: 0,
+ getBoundingClientRect: () => ({ top: 580, height: 0 }),
+ } as HTMLElement;
+ const querySelector = vi.fn((selector: string) => {
+ if (selector === '[data-chat-composer-stack]') return composerStack;
+ if (selector === '[data-composer-center-group]') return centerGroup;
+ return null;
+ });
const overlay = {
querySelector,
getBoundingClientRect: () => ({ bottom: 800 }),
} as unknown as HTMLElement;
- expect(measureComposerStackTopOffset(overlay)).toBe(180);
+ expect(measureMessageStreamIndicatorClearanceOffset(overlay)).toBe(180);
expect(querySelector).toHaveBeenCalledWith('[data-chat-composer-stack]');
+ expect(querySelector).toHaveBeenCalledWith('[data-composer-center-group]');
+ });
+
+ it('stacks the indicator above an occupied composer center group', () => {
+ const composerStack = {
+ getBoundingClientRect: () => ({ top: 620 }),
+ } as HTMLElement;
+ const centerGroup = {
+ childElementCount: 1,
+ getBoundingClientRect: () => ({ top: 580, height: 32 }),
+ } as HTMLElement;
+ const overlay = {
+ querySelector: (selector: string) =>
+ selector === '[data-chat-composer-stack]'
+ ? composerStack
+ : selector === '[data-composer-center-group]'
+ ? centerGroup
+ : null,
+ getBoundingClientRect: () => ({ bottom: 800 }),
+ } as unknown as HTMLElement;
+
+ const clearanceOffset = measureMessageStreamIndicatorClearanceOffset(overlay);
+ expect(clearanceOffset).toBe(220);
+ const indicatorBottomOffset = resolveMessageStreamIndicatorBottomOffset({
+ bottomPadding: 206,
+ bottomCenterClearanceOffset: clearanceOffset,
+ });
+ expect(indicatorBottomOffset).toBe(226);
+ expect(580 - (800 - indicatorBottomOffset)).toBe(6);
+ });
+
+ it('stacks the indicator above an expanded plan flyout', () => {
+ const composerStack = {
+ getBoundingClientRect: () => ({ top: 620 }),
+ } as HTMLElement;
+ const centerGroup = {
+ childElementCount: 1,
+ getBoundingClientRect: () => ({ top: 580, height: 32 }),
+ } as HTMLElement;
+ const planFlyout = {
+ getBoundingClientRect: () => ({ top: 300, height: 272 }),
+ } as HTMLElement;
+ const overlay = {
+ querySelector: (selector: string) =>
+ selector === '[data-chat-composer-stack]'
+ ? composerStack
+ : selector === '[data-composer-center-group]'
+ ? centerGroup
+ : selector === '[data-plan-flyout-positioner="composer"]'
+ ? planFlyout
+ : null,
+ getBoundingClientRect: () => ({ bottom: 800 }),
+ } as unknown as HTMLElement;
+
+ const clearanceOffset = measureMessageStreamIndicatorClearanceOffset(overlay);
+ expect(clearanceOffset).toBe(500);
+ const indicatorBottomOffset = resolveMessageStreamIndicatorBottomOffset({
+ bottomPadding: 206,
+ bottomCenterClearanceOffset: clearanceOffset,
+ });
+ expect(indicatorBottomOffset).toBe(506);
+ expect(300 - (800 - indicatorBottomOffset)).toBe(6);
+ });
+
+ it('observes the inner center lane because it can resize without changing the overlay', () => {
+ const composerStack = {} as HTMLElement;
+ const centerGroup = {} as HTMLElement;
+ const planFlyout = {} as HTMLElement;
+ const overlay = {
+ querySelector: (selector: string) =>
+ selector === '[data-chat-composer-stack]'
+ ? composerStack
+ : selector === '[data-composer-center-group]'
+ ? centerGroup
+ : selector === '[data-plan-flyout-positioner="composer"]'
+ ? planFlyout
+ : null,
+ } as unknown as HTMLElement;
+
+ expect(getMessageStreamIndicatorResizeTargets(overlay)).toEqual([
+ overlay,
+ composerStack,
+ centerGroup,
+ planFlyout,
+ ]);
});
});
diff --git a/apps/desktop/src/renderer/components/chat/messageStreamIndicatorPosition.ts b/apps/desktop/src/renderer/components/chat/messageStreamIndicatorPosition.ts
index 485f7ded2b..1a83f505c7 100644
--- a/apps/desktop/src/renderer/components/chat/messageStreamIndicatorPosition.ts
+++ b/apps/desktop/src/renderer/components/chat/messageStreamIndicatorPosition.ts
@@ -3,22 +3,64 @@ const LEGACY_STATUS_ROW_OFFSET_PX = 56;
const MIN_BOTTOM_OFFSET_PX = 12;
const COMPOSER_GAP_PX = 6;
+const COMPOSER_STACK_SELECTOR = '[data-chat-composer-stack]';
+const COMPOSER_CENTER_GROUP_SELECTOR = '[data-composer-center-group]';
+const PLAN_FLYOUT_SELECTOR = '[data-plan-flyout-positioner="composer"]';
+
export function resolveMessageStreamIndicatorBottomOffset({
bottomPadding,
- composerStackTopOffset,
+ bottomCenterClearanceOffset,
}: {
bottomPadding?: number;
- composerStackTopOffset?: number;
+ bottomCenterClearanceOffset?: number;
}): number {
- if (composerStackTopOffset != null) return composerStackTopOffset + COMPOSER_GAP_PX;
+ if (bottomCenterClearanceOffset != null) return bottomCenterClearanceOffset + COMPOSER_GAP_PX;
const resolvedBottomPadding = bottomPadding ?? DEFAULT_BOTTOM_PADDING_PX;
return Math.max(resolvedBottomPadding - LEGACY_STATUS_ROW_OFFSET_PX, MIN_BOTTOM_OFFSET_PX);
}
-export function measureComposerStackTopOffset(overlayEl: HTMLElement): number | undefined {
- const composerStack = overlayEl.querySelector<HTMLElement>('[data-chat-composer-stack]');
+/**
+ * Measure the topmost occupied layer in the composer's bottom-center lane.
+ *
+ * The running-status row deliberately does not move message navigation: its
+ * left/right text leaves the center lane free. Pinned plans and the expanded
+ * controlled banner do occupy that lane, so the jump/new-message pill must
+ * stack above them instead of sharing their 32px band.
+ */
+export function measureMessageStreamIndicatorClearanceOffset(
+ overlayEl: HTMLElement,
+): number | undefined {
+ const composerStack = overlayEl.querySelector<HTMLElement>(COMPOSER_STACK_SELECTOR);
if (!composerStack) return undefined;
- return overlayEl.getBoundingClientRect().bottom - composerStack.getBoundingClientRect().top;
+ let clearanceTop = composerStack.getBoundingClientRect().top;
+ const centerGroup = overlayEl.querySelector<HTMLElement>(COMPOSER_CENTER_GROUP_SELECTOR);
+ if (centerGroup && centerGroup.childElementCount > 0) {
+ const centerGroupRect = centerGroup.getBoundingClientRect();
+ if (centerGroupRect.height > 0) clearanceTop = Math.min(clearanceTop, centerGroupRect.top);
+ }
+ const planFlyout = overlayEl.querySelector<HTMLElement>(PLAN_FLYOUT_SELECTOR);
+ if (planFlyout) {
+ const planFlyoutRect = planFlyout.getBoundingClientRect();
+ if (planFlyoutRect.height > 0) clearanceTop = Math.min(clearanceTop, planFlyoutRect.top);
+ }
+
+ return overlayEl.getBoundingClientRect().bottom - clearanceTop;
+}
+
+/**
+ * The center group can gain or lose a plan while the outer overlay keeps the
+ * same height (the running-status row already owns that grid row). The plan
+ * flyout is absolutely positioned, so observe it directly after it mounts.
+ */
+export function getMessageStreamIndicatorResizeTargets(overlayEl: HTMLElement): HTMLElement[] {
+ const targets = [overlayEl];
+ const composerStack = overlayEl.querySelector<HTMLElement>(COMPOSER_STACK_SELECTOR);
+ const centerGroup = overlayEl.querySelector<HTMLElement>(COMPOSER_CENTER_GROUP_SELECTOR);
+ const planFlyout = overlayEl.querySelector<HTMLElement>(PLAN_FLYOUT_SELECTOR);
+ if (composerStack) targets.push(composerStack);
+ if (centerGroup) targets.push(centerGroup);
+ if (planFlyout) targets.push(planFlyout);
+ return targets;
}
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index dad554efe6..595afdb77a 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -77,7 +77,10 @@ import {
readSendFollowCancelGeneration,
tryRequestFollowLatest,
} from '@/components/chat/autoFollowIntent';
-import { measureComposerStackTopOffset } from '@/components/chat/messageStreamIndicatorPosition';
+import {
+ getMessageStreamIndicatorResizeTargets,
+ measureMessageStreamIndicatorClearanceOffset,
+} from '@/components/chat/messageStreamIndicatorPosition';
import { ShareSelectionBar } from '@/components/chat/ShareSelectionBar';
import {
shareSelectionStore,
@@ -1279,9 +1282,9 @@ export function CCAgentSessionView({
setOverlayEl(node);
}, []);
const [overlayHeight, setOverlayHeight] = useState(200);
- const [composerStackTopOffset, setComposerStackTopOffset] = useState<number | undefined>(
- undefined,
- );
+ const [bottomCenterClearanceOffset, setBottomCenterClearanceOffset] = useState<
+ number | undefined
+ >(undefined);
const [inlinePlanVisibilityState, setInlinePlanVisibilityState] = useState<{
sessionId: string | undefined;
value: InlinePlanVisibility | null;
@@ -1310,18 +1313,37 @@ export function CCAgentSessionView({
useEffect(() => {
if (!overlayEl) return;
const measureOverlay = () => {
- // 状态行会动态出现 / 收起,overlay 总高度不等于 composer 栈顶边。
- // 直接量完整 composer 栈(含计划模式提示)到 overlay 底边的距离,
- // 让消息流悬浮按钮不受状态行或输入框内部状态高度影响。
+ // 状态行会动态出现 / 收起,overlay 总高度不等于底部中央控件的避让边界。
+ // 空中央行仍以 composer 栈为锚;步骤 / 接管胶囊在场时改取中央组顶边,
+ // 让消息流悬浮按钮与它们纵向成栈,而不是共享同一块 32px 区域。
setOverlayHeight(overlayEl.offsetHeight);
- setComposerStackTopOffset(measureComposerStackTopOffset(overlayEl));
+ setBottomCenterClearanceOffset(measureMessageStreamIndicatorClearanceOffset(overlayEl));
};
- // Seed with the current height so the first paint after remount uses the
- // real value (not the stale state from the previous mount).
- measureOverlay();
const ro = new ResizeObserver(measureOverlay);
- ro.observe(overlayEl);
- return () => ro.disconnect();
+ let observedTargets = new Set<HTMLElement>();
+ const syncResizeTargetsAndMeasure = () => {
+ const nextTargets = new Set(getMessageStreamIndicatorResizeTargets(overlayEl));
+ for (const target of observedTargets) {
+ if (!nextTargets.has(target)) ro.unobserve(target);
+ }
+ for (const target of nextTargets) {
+ if (!observedTargets.has(target)) ro.observe(target);
+ }
+ observedTargets = nextTargets;
+ measureOverlay();
+ };
+
+ // Seed with the current geometry so the first paint after remount does not
+ // reuse stale state. The plan flyout is absolutely positioned and mounts
+ // only on hover/click, so its insertion does not resize the center group;
+ // resync observed targets whenever that subtree changes.
+ syncResizeTargetsAndMeasure();
+ const mutationObserver = new MutationObserver(syncResizeTargetsAndMeasure);
+ mutationObserver.observe(overlayEl, { childList: true, subtree: true });
+ return () => {
+ mutationObserver.disconnect();
+ ro.disconnect();
+ };
}, [overlayEl]);
// F-FP-5: 点击 workingDir → 在系统文件管理器里直接打开目录(复用 shell:open-path IPC)。
@@ -4101,7 +4123,7 @@ export function CCAgentSessionView({
hasMoreMessages={hasMoreMessages}
historyWindowHasIsland={historyWindowHasIsland}
bottomPadding={overlayHeight}
- composerStackTopOffset={composerStackTopOffset}
+ bottomCenterClearanceOffset={bottomCenterClearanceOffset}
contentWidth={messageWidth}
getContentWidth={getMessageWidth}
focusMessageClientId={focusedMessageTarget?.clientId ?? null}