From 33b133601ba95bde778ddfd6b418b8519dea5bbd Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:21:23 -0800 Subject: [PATCH] fix(native-chat): keep a consistent gap above an answer's action row (#42942) --- .../actions/NativeChatAgentControls.tsx | 5 +- .../rows/NativeChatActionsGap.fixture.tsx | 73 +++++++++++++++++++ .../rows/NativeChatAssistantMessageRow.tsx | 2 +- .../native-chat-actions-gap.spec.ts | 41 +++++++++++ 4 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 src/renderer/src/components/native-chat/messages/rows/NativeChatActionsGap.fixture.tsx create mode 100644 tests/component-fixtures/native-chat-actions-gap.spec.ts diff --git a/src/renderer/src/components/native-chat/messages/actions/NativeChatAgentControls.tsx b/src/renderer/src/components/native-chat/messages/actions/NativeChatAgentControls.tsx index ce95b2ba119..5d8ffbd0f9b 100644 --- a/src/renderer/src/components/native-chat/messages/actions/NativeChatAgentControls.tsx +++ b/src/renderer/src/components/native-chat/messages/actions/NativeChatAgentControls.tsx @@ -21,8 +21,9 @@ export function NativeChatAgentControls({ }): React.JSX.Element { const t = useTranslate() return ( - // Row chrome, not transcript: find skips it. -
+ // Row chrome, not transcript: find skips it. The row owns a minimum gap above it, so every answer + // gets at least this much: it collapses with the last block's bottom margin, and a larger one wins. +
{/* A visual line means nothing pasted outside Orca, so the copy leaves it out. An image-only response has nothing to copy, so it has no Copy. */} {markdown.length > 0 ? ( diff --git a/src/renderer/src/components/native-chat/messages/rows/NativeChatActionsGap.fixture.tsx b/src/renderer/src/components/native-chat/messages/rows/NativeChatActionsGap.fixture.tsx new file mode 100644 index 00000000000..186d78e074f --- /dev/null +++ b/src/renderer/src/components/native-chat/messages/rows/NativeChatActionsGap.fixture.tsx @@ -0,0 +1,73 @@ +import { defineFixture } from '../../../../component-fixtures/component-fixture' +import { NativeChatMessageList } from '../../NativeChatMessageList' +import type { NativeChatLiveSession } from '../../session/terminal/read/native-chat-live-session-contract' +import type { NativeChatMessage } from '../../../../../../shared/native-chat/native-chat-types' +import { NativeChatVisualOwnerContext } from '../../media/visuals/native-chat-visual-owner' +import { + NATIVE_CHAT_APPEARANCE_ROOT_CLASS, + nativeChatAppearanceStyle +} from '../../appearance/native-chat-appearance-style' + +// Every answer keeps at least the same gap above its actions, whatever it ends with. +const owner = { + target: { kind: 'local' as const }, + sessionId: 'actions-gap', + worktreeId: 'actions-gap' +} + +const ORDER = ['ask', 'reply', 'check', 'last'] + +function message(id: string, role: NativeChatMessage['role'], text: string): NativeChatMessage { + return { + id, + role, + timestamp: 1_800_000_000_000 + ORDER.indexOf(id) * 60_000, + source: 'transcript', + blocks: [{ type: 'text', text }] + } +} + +function ActionsGap({ last }: { last: string }): React.JSX.Element { + const session: NativeChatLiveSession = { + agent: 'claude', + sessionId: 'actions-gap', + status: 'ready', + readPhase: 'ready', + hasMore: false, + loadingEarlier: false, + olderHistoryGeneration: 0, + loadEarlier: async () => 'applied', + messages: [ + message('ask', 'user', 'Anything new on the board?'), + message('reply', 'assistant', 'Two items moved to done.'), + message('check', 'user', 'Check again.'), + message('last', 'assistant', last) + ] + } + const theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light' + return ( + +
+ +
+
+ ) +} + +export const paragraph = defineFixture({ + width: 560, + render: () => +}) + +export const list = defineFixture({ + width: 560, + render: () => +}) + +export const code = defineFixture({ + width: 560, + render: () => +}) diff --git a/src/renderer/src/components/native-chat/messages/rows/NativeChatAssistantMessageRow.tsx b/src/renderer/src/components/native-chat/messages/rows/NativeChatAssistantMessageRow.tsx index fd34b506bea..9230880e4fb 100644 --- a/src/renderer/src/components/native-chat/messages/rows/NativeChatAssistantMessageRow.tsx +++ b/src/renderer/src/components/native-chat/messages/rows/NativeChatAssistantMessageRow.tsx @@ -121,7 +121,7 @@ export function NativeChatAssistantMessageRow({ ) : null } className={cn( - 'mt-1 w-fit select-none', + 'w-fit select-none', !latestResponse && fork?.pendingItemId !== message.id && 'transition-opacity can-hover:pointer-events-none can-hover:opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100', diff --git a/tests/component-fixtures/native-chat-actions-gap.spec.ts b/tests/component-fixtures/native-chat-actions-gap.spec.ts new file mode 100644 index 00000000000..e99ee66d101 --- /dev/null +++ b/tests/component-fixtures/native-chat-actions-gap.spec.ts @@ -0,0 +1,41 @@ +import { expect, test, type Locator, type Page } from '@playwright/test' + +// The visible gap between an answer's last block and its actions, at the default chat typography. +// Before the actions owned the gap, a paragraph got 4px and a list 10px. +test.use({ viewport: { width: 1000, height: 720 } }) + +const GAP = 12 + +// The block itself, not whichever inline element holds its text. +const LAST_BLOCK: Record Locator> = { + paragraph: (page) => + page.getByRole('paragraph').filter({ hasText: 'Nothing changed since the last check.' }), + list: (page) => page.getByRole('listitem').filter({ hasText: 'Release notes' }) +} + +for (const [ending, lastBlock] of Object.entries(LAST_BLOCK)) { + test(`an answer ending in a ${ending} keeps a ${GAP}px gap above its actions`, async ({ + page + }) => { + await page.goto( + `/fixtures.html?id=native-chat/messages/rows/NativeChatActionsGap:${ending}&theme=light` + ) + // A cold server compiles the whole chat graph on first load. + await expect(page.locator('html')).toHaveAttribute('data-fixture-state', 'ready', { + timeout: 60_000 + }) + const earlier = page.getByText('Two items moved to done.', { exact: true }) + await expect(earlier).toHaveCSS('font-size', '13px') + await expect(earlier).toHaveCSS('line-height', '20px') + const block = await lastBlock(page).boundingBox() + // The action the reader sees, not whatever box happens to wrap it. + const action = await page + .getByRole('button', { name: 'Scroll this message to top' }) + .last() + .boundingBox() + if (!block || !action) { + throw new Error('The answer or its actions did not render') + } + expect(action.y - (block.y + block.height)).toBeCloseTo(GAP, 0) + }) +}