Skip to content

Commit 346d34f

Browse files
committed
fix(chat): keep approvals visible while scrolled
1 parent 97265fd commit 346d34f

2 files changed

Lines changed: 101 additions & 61 deletions

File tree

‎webview-ui/src/components/chat/ChatView.tsx‎

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
16411641
vscode.postMessage({ type: "condenseTaskContextRequest", text: taskId })
16421642
}
16431643

1644-
const areButtonsVisible = showScrollToBottom || primaryButtonText || secondaryButtonText
1644+
const hasApprovalButtons = Boolean(primaryButtonText || secondaryButtonText)
1645+
const areButtonsVisible = showScrollToBottom || hasApprovalButtons
16451646
const currentTaskAggregatedCosts = currentTaskId ? aggregatedCostsMap.get(currentTaskId) : undefined
16461647

16471648
return (
@@ -1735,17 +1736,23 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
17351736
className={`flex h-9 items-center mb-1 px-[15px] ${
17361737
showScrollToBottom ? "opacity-100" : enableButtons ? "opacity-100" : "opacity-50"
17371738
}`}>
1738-
{showScrollToBottom ? (
1739+
{showScrollToBottom && (
17391740
<>
17401741
<StandardTooltip content={t("chat:scrollToBottom")}>
17411742
<Button
17421743
variant="secondary"
1743-
className={hasLatestCheckpoint ? "flex-1 mr-[6px]" : "flex-[2]"}
1744+
className={
1745+
hasApprovalButtons
1746+
? "w-9 shrink-0 mr-[6px]"
1747+
: hasLatestCheckpoint
1748+
? "flex-1 mr-[6px]"
1749+
: "flex-[2]"
1750+
}
17441751
onClick={handleScrollToBottomAndResetCheckpointCursor}>
17451752
<span className="codicon codicon-chevron-down"></span>
17461753
</Button>
17471754
</StandardTooltip>
1748-
{hasLatestCheckpoint && (
1755+
{hasLatestCheckpoint && !hasApprovalButtons && (
17491756
<StandardTooltip content={t("chat:scrollToLatestCheckpoint")}>
17501757
<Button
17511758
variant="secondary"
@@ -1757,63 +1764,61 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
17571764
</StandardTooltip>
17581765
)}
17591766
</>
1760-
) : (
1761-
<>
1762-
{primaryButtonText && (
1763-
<StandardTooltip
1764-
content={
1765-
primaryButtonText === t("chat:retry.title")
1766-
? t("chat:retry.tooltip")
1767-
: primaryButtonText === t("chat:save.title")
1768-
? t("chat:save.tooltip")
1769-
: primaryButtonText === t("chat:approve.title")
1770-
? t("chat:approve.tooltip")
1771-
: primaryButtonText === t("chat:runCommand.title")
1772-
? t("chat:runCommand.tooltip")
1773-
: primaryButtonText === t("chat:startNewTask.title")
1774-
? t("chat:startNewTask.tooltip")
1775-
: primaryButtonText === t("chat:resumeTask.title")
1776-
? t("chat:resumeTask.tooltip")
1777-
: primaryButtonText ===
1778-
t("chat:proceedAnyways.title")
1779-
? t("chat:proceedAnyways.tooltip")
1780-
: primaryButtonText ===
1781-
t("chat:proceedWhileRunning.title")
1782-
? t("chat:proceedWhileRunning.tooltip")
1783-
: undefined
1784-
}>
1785-
<Button
1786-
variant="primary"
1787-
disabled={!enableButtons}
1788-
className={secondaryButtonText ? "flex-1 mr-[6px]" : "flex-[2] mr-0"}
1789-
onClick={() => handlePrimaryButtonClick(inputValue, selectedImages)}>
1790-
{primaryButtonText}
1791-
</Button>
1792-
</StandardTooltip>
1793-
)}
1794-
{secondaryButtonText && (
1795-
<StandardTooltip
1796-
content={
1797-
secondaryButtonText === t("chat:startNewTask.title")
1798-
? t("chat:startNewTask.tooltip")
1799-
: secondaryButtonText === t("chat:reject.title")
1800-
? t("chat:reject.tooltip")
1801-
: secondaryButtonText === t("chat:terminate.title")
1802-
? t("chat:terminate.tooltip")
1803-
: secondaryButtonText === t("chat:killCommand.title")
1804-
? t("chat:killCommand.tooltip")
1805-
: undefined
1806-
}>
1807-
<Button
1808-
variant="secondary"
1809-
disabled={!enableButtons}
1810-
className="flex-1 ml-[6px]"
1811-
onClick={() => handleSecondaryButtonClick(inputValue, selectedImages)}>
1812-
{secondaryButtonText}
1813-
</Button>
1814-
</StandardTooltip>
1815-
)}
1816-
</>
1767+
)}
1768+
{primaryButtonText && (
1769+
<StandardTooltip
1770+
content={
1771+
primaryButtonText === t("chat:retry.title")
1772+
? t("chat:retry.tooltip")
1773+
: primaryButtonText === t("chat:save.title")
1774+
? t("chat:save.tooltip")
1775+
: primaryButtonText === t("chat:approve.title")
1776+
? t("chat:approve.tooltip")
1777+
: primaryButtonText === t("chat:runCommand.title")
1778+
? t("chat:runCommand.tooltip")
1779+
: primaryButtonText === t("chat:startNewTask.title")
1780+
? t("chat:startNewTask.tooltip")
1781+
: primaryButtonText === t("chat:resumeTask.title")
1782+
? t("chat:resumeTask.tooltip")
1783+
: primaryButtonText === t("chat:proceedAnyways.title")
1784+
? t("chat:proceedAnyways.tooltip")
1785+
: primaryButtonText ===
1786+
t("chat:proceedWhileRunning.title")
1787+
? t("chat:proceedWhileRunning.tooltip")
1788+
: primaryButtonText
1789+
}>
1790+
<Button
1791+
variant="primary"
1792+
disabled={!enableButtons}
1793+
className={
1794+
secondaryButtonText ? "min-w-0 flex-1 mr-[6px]" : "min-w-0 flex-[2] mr-0"
1795+
}
1796+
onClick={() => handlePrimaryButtonClick(inputValue, selectedImages)}>
1797+
<span className="min-w-0 truncate">{primaryButtonText}</span>
1798+
</Button>
1799+
</StandardTooltip>
1800+
)}
1801+
{secondaryButtonText && (
1802+
<StandardTooltip
1803+
content={
1804+
secondaryButtonText === t("chat:startNewTask.title")
1805+
? t("chat:startNewTask.tooltip")
1806+
: secondaryButtonText === t("chat:reject.title")
1807+
? t("chat:reject.tooltip")
1808+
: secondaryButtonText === t("chat:terminate.title")
1809+
? t("chat:terminate.tooltip")
1810+
: secondaryButtonText === t("chat:killCommand.title")
1811+
? t("chat:killCommand.tooltip")
1812+
: secondaryButtonText
1813+
}>
1814+
<Button
1815+
variant="secondary"
1816+
disabled={!enableButtons}
1817+
className="min-w-0 flex-1 ml-[6px]"
1818+
onClick={() => handleSecondaryButtonClick(inputValue, selectedImages)}>
1819+
<span className="min-w-0 truncate">{secondaryButtonText}</span>
1820+
</Button>
1821+
</StandardTooltip>
18171822
)}
18181823
</div>
18191824
)}

‎webview-ui/src/components/chat/__tests__/ChatView.scroll-debug-repro.spec.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,41 @@ describe("ChatView scroll behavior regression coverage", () => {
502502
await expectChevronVisible()
503503
})
504504

505+
it("keeps pending approval controls visible while browsing history", async () => {
506+
const baseTs = Date.now() - 3_000
507+
const initialMessages = buildMessagesWithCheckpoint(baseTs)
508+
await hydrate(2, initialMessages)
509+
await waitForCalls(2)
510+
await waitForCallsSettled()
511+
512+
const scrollable = getScrollable()
513+
await act(async () => {
514+
fireEvent.wheel(scrollable, { deltaY: -120 })
515+
})
516+
await expectChevronVisible()
517+
518+
await act(async () => {
519+
postState([
520+
...initialMessages,
521+
{
522+
type: "ask",
523+
ask: "tool",
524+
ts: baseTs + 4,
525+
text: JSON.stringify({ tool: "finishTask" }),
526+
},
527+
])
528+
})
529+
await flushEffects()
530+
531+
expect(document.querySelector(".codicon-chevron-down")).toBeTruthy()
532+
expect(document.querySelector("button[aria-label='chat:scrollToLatestCheckpoint']")).toBeNull()
533+
expect(
534+
Array.from(document.querySelectorAll("button")).some(
535+
(button) => button.textContent === "chat:completeSubtaskAndReturn",
536+
),
537+
).toBe(true)
538+
})
539+
505540
it("hydration completion cannot override user escape hatch", async () => {
506541
await hydrate(Number.POSITIVE_INFINITY)
507542
await waitForCalls(1)

0 commit comments

Comments
 (0)