From 76067e89810c4cbf554d61afbf23d7b5f72b01a7 Mon Sep 17 00:00:00 2001 From: bunnysayzz Date: Thu, 6 Aug 2026 11:51:16 +0530 Subject: [PATCH] fix: keep code-block toolbar within panel bounds when sidebar is narrowed Code-block header bars (Copy/Run/Enter buttons) overflowed past the panel edge when the sidebar was narrowed, hiding the action buttons. Flexbox's default min-width:auto prevented the toolbar's flex children from shrinking. Allow the title side to shrink and truncate (min-w-0) while pinning the action buttons (shrink-0), and let the header wrap on very narrow widths. Fixes #13085 --- .../StepContainerPreToolbar/index.test.tsx | 79 +++++++++++++++++++ .../StepContainerPreToolbar/index.tsx | 6 +- 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.test.tsx diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.test.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.test.tsx new file mode 100644 index 00000000000..c30a46465f1 --- /dev/null +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.test.tsx @@ -0,0 +1,79 @@ +import { render } from "@testing-library/react"; +import { describe, expect, it, vi } from "vitest"; +import { StepContainerPreToolbar } from "./index"; + +vi.mock("../../../context/IdeMessenger", () => { + const { createContext } = require("react"); + return { + IdeMessengerContext: createContext({ + ide: { + getCurrentFile: vi.fn().mockResolvedValue(undefined), + showToast: vi.fn(), + showLines: vi.fn(), + }, + post: vi.fn(), + }), + }; +}); + +vi.mock("../../../redux/hooks", () => ({ + useAppSelector: () => ({}), +})); + +vi.mock("../../../hooks/useWebviewListener", () => ({ + useWebviewListener: () => {}, +})); + +vi.mock("../../../hooks/useIdeMessengerRequest", () => ({ + useIdeMessengerRequest: () => ({ + result: undefined, + refresh: vi.fn(), + isLoading: false, + }), +})); + +vi.mock("../../../redux/selectors/selectToolCalls", () => ({ + selectToolCallById: () => undefined, +})); + +vi.mock("../../../redux/slices/sessionSlice", () => ({ + selectApplyStateByStreamId: () => undefined, + selectApplyStateByToolCallId: () => undefined, +})); + +describe("StepContainerPreToolbar", () => { + const baseProps = { + codeBlockContent: "console.log('hello')", + language: "javascript", + codeBlockIndex: 0, + isLastCodeblock: true, + codeBlockStreamId: "stream-1", + }; + + it("renders the code block", () => { + const { container } = render( + +
console.log('hello')
+
, + ); + expect(container).toBeTruthy(); + }); + + it("lets the title side shrink and pins the action buttons so the toolbar never overflows the panel", () => { + const { container } = render( + +
console.log('hello')
+
, + ); + + const titleContainer = [...container.querySelectorAll("div")].find((el) => + el.classList.contains("min-w-0"), + ); + expect(titleContainer).toBeTruthy(); + + const actionsContainer = [...container.querySelectorAll("div")].find((el) => + el.classList.contains("shrink-0"), + ); + expect(actionsContainer).toBeTruthy(); + }); +}); diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index f9d268ccc3f..446b29f2139 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -294,10 +294,10 @@ export function StepContainerPreToolbar({ return (
-
+
{toolCallStatusIcon} -
+
{!isGeneratingCodeBlock && (