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): 列表模式任务操作按钮对齐文字模式 (#1446)

Dashb136cc3a1130
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
index d77abe32db..08a070ed63 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
@@ -1011,13 +1011,13 @@ function TimeActionsSlot({
}) {
const { t } = useTranslation();
return (
- <div className="relative ml-auto flex h-5 shrink-0 items-center justify-end">
+ <div className="group/slot relative ml-auto flex h-5 shrink-0 items-center justify-end">
{/* 默认内容:worktree + 时间;hover / 菜单打开 / archivePending 时淡出让位给操作钮。 */}
<div
className={cn(
// duration 与操作钮的渐显同拍(120ms),让位/回归一进一出同步。
'flex items-center gap-1 transition-opacity duration-[120ms]',
- !archivePending && 'group-hover/card:opacity-0',
+ !archivePending && 'group-hover/card:opacity-0 group-focus-within/slot:opacity-0',
(menuOpen || yieldToOrdinalBadge) && 'opacity-0',
// 确认胶囊覆盖同一槽位时立即隐藏日期,避免 120ms 淡出期间文字叠在一起。
archivePending && 'invisible opacity-0',
@@ -1069,22 +1069,34 @@ function TimeActionsSlot({
'transition-opacity duration-[120ms]',
menuOpen
? 'opacity-100'
- : 'pointer-events-none opacity-0 group-hover/card:pointer-events-auto group-hover/card:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100',
+ : 'pointer-events-none opacity-0 group-hover/card:pointer-events-auto group-hover/card:opacity-100 group-focus-within/slot:pointer-events-auto group-focus-within/slot:opacity-100',
)}
>
- <CardAction label={t('ccAgent.sidebar.sessionMenu.moreActions')} onClick={onOpenMenu}>
- <EllipsisVertical size={13} strokeWidth={2} />
+ <CardAction
+ variant="list"
+ isActive={isActive}
+ label={t('ccAgent.sidebar.sessionMenu.moreActions')}
+ onClick={onOpenMenu}
+ >
+ <EllipsisVertical size={14} strokeWidth={2} />
</CardAction>
{isArchived && canUnarchive ? (
- <CardAction label={t('ccAgent.sidebar.sessionMenu.unarchive')} onClick={() => onUnarchive()}>
- <Undo size={13} strokeWidth={2} />
+ <CardAction
+ variant="list"
+ isActive={isActive}
+ label={t('ccAgent.sidebar.sessionMenu.unarchive')}
+ onClick={() => onUnarchive()}
+ >
+ <Undo size={14} strokeWidth={2} />
</CardAction>
) : canQuickArchive ? (
<CardAction
+ variant="list"
+ isActive={isActive}
label={t('ccAgent.sidebar.sessionMenu.archived')}
onClick={() => setArchivePending(true)}
>
- <Archive size={13} strokeWidth={2} />
+ <Archive size={14} strokeWidth={2} />
</CardAction>
) : null}
</div>
@@ -1093,12 +1105,16 @@ function TimeActionsSlot({
);
}
-/** 卡片右上角 hover action 钮——白底小方钮,对照 redesign 稿 .xdtsb-act。 */
+/** 卡片右上角 hover action 钮;list 变体复用文字模式的轻量行内按钮。 */
function CardAction({
+ variant = 'card',
+ isActive = false,
label,
onClick,
children,
}: {
+ variant?: 'card' | 'list';
+ isActive?: boolean;
label: string;
onClick: (e: ReactMouseEvent<HTMLButtonElement>) => void;
children: ReactNode;
@@ -1114,10 +1130,20 @@ function CardAction({
onPointerDown={(e) => e.stopPropagation()}
onDoubleClick={(e) => e.stopPropagation()}
className={cn(
- 'flex size-6 items-center justify-center rounded-[7px]',
- 'bg-[var(--cmd-palette-bg)] text-[var(--text-tertiary)]',
- 'border border-sidebar-border',
- 'hover:bg-sidebar-item-hover hover:text-foreground focus:outline-none',
+ variant === 'list'
+ ? cn(
+ 'shrink-0 size-5 flex items-center justify-center rounded-md',
+ 'focus:outline-none',
+ isActive
+ ? 'text-sidebar-item-active-foreground hover:text-sidebar-item-active-foreground hover:bg-[color-mix(in_srgb,var(--sidebar-item-active-foreground)_14%,transparent)]'
+ : 'text-sidebar-action-icon hover:bg-sidebar-item-hover hover:text-foreground',
+ )
+ : cn(
+ 'flex size-6 items-center justify-center rounded-[7px]',
+ 'bg-[var(--cmd-palette-bg)] text-[var(--text-tertiary)]',
+ 'border border-sidebar-border',
+ 'hover:bg-sidebar-item-hover hover:text-foreground focus:outline-none',
+ ),
)}
>
{children}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
index 882df45d4a..845397be5c 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
@@ -448,6 +448,69 @@ describe('SessionCard visual cases', () => {
expect(screen.getByText('已归档的历史分析任务')).toBeTruthy();
});
+ it('matches text-mode action chrome in list mode while preserving card buttons', () => {
+ const visualCase = sessionCardVisualCases.find((item) => item.id === 'short-idle-cc');
+ if (!visualCase) throw new Error('Missing idle visual case');
+
+ const commonProps = {
+ session: visualCase.session,
+ isActive: false,
+ isRunning: false,
+ isAttached: false,
+ hasAttentionNotification: false,
+ isSelected: false,
+ onClick: vi.fn(),
+ onAction: vi.fn(),
+ onRename: vi.fn(),
+ onTogglePin: vi.fn(),
+ projectOptions: [],
+ };
+ const moreActionsName = /^(?:更多操作|ccAgent\.sidebar\.sessionMenu\.moreActions)$/;
+
+ const { container: listContainer } = render(
+ createElement(SessionCard, { ...commonProps, variant: 'list' }),
+ );
+ const listMore = within(listContainer).getByRole('button', {
+ name: moreActionsName,
+ });
+ const listArchive = within(listContainer).getByRole('button', { name: '归档' });
+ for (const action of [listMore, listArchive]) {
+ expect(action.className).toContain('size-5');
+ expect(action.className).toContain('rounded-md');
+ expect(action.className).toContain('text-sidebar-action-icon');
+ expect(action.className).not.toContain('size-6');
+ expect(action.className).not.toContain('bg-[var(--cmd-palette-bg)]');
+ expect(action.className).not.toContain('border-sidebar-border');
+ expect(action.querySelector('svg')?.getAttribute('width')).toBe('14');
+ }
+ const listTimeFade = listContainer.querySelector('time')?.parentElement;
+ expect(listTimeFade?.className).toContain('group-focus-within/slot:opacity-0');
+ expect(listTimeFade?.parentElement?.className).toContain('group/slot');
+ cleanup();
+
+ const { container: activeListContainer } = render(
+ createElement(SessionCard, { ...commonProps, variant: 'list', isActive: true }),
+ );
+ const activeListMore = within(activeListContainer).getByRole('button', {
+ name: moreActionsName,
+ });
+ expect(activeListMore.className).toContain('text-sidebar-item-active-foreground');
+ expect(activeListMore.className).toContain(
+ 'hover:bg-[color-mix(in_srgb,var(--sidebar-item-active-foreground)_14%,transparent)]',
+ );
+ cleanup();
+
+ const { container: cardContainer } = render(createElement(SessionCard, commonProps));
+ const cardMore = within(cardContainer).getByRole('button', {
+ name: moreActionsName,
+ });
+ expect(cardMore.className).toContain('size-6');
+ expect(cardMore.className).toContain('bg-[var(--cmd-palette-bg)]');
+ expect(cardMore.className).toContain('border-sidebar-border');
+ expect(cardMore.className).not.toContain('size-5');
+ expect(cardMore.querySelector('svg')?.getAttribute('width')).toBe('13');
+ });
+
it.each(['list', 'card'] as const)('keeps the %s archive confirmation pill on one line', (variant) => {
const visualCase = sessionCardVisualCases.find((item) => item.id === 'short-idle-cc');
if (!visualCase) throw new Error('Missing idle visual case');