From 979c2473c61747157e65e1dcd33fd73ccfe404ad Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 6 Nov 2024 20:35:29 -0800 Subject: [PATCH] feat: collapsed codeblock by default --- core/protocol/index.ts | 8 ++--- .../components/markdown/CodeBlockToolbar.tsx | 30 +++++++++++++++---- .../components/markdown/PreWithToolbar.tsx | 13 +++++++- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/core/protocol/index.ts b/core/protocol/index.ts index 495c2fb90..522b52934 100644 --- a/core/protocol/index.ts +++ b/core/protocol/index.ts @@ -1,13 +1,13 @@ import { ToCoreFromWebviewProtocol, ToWebviewFromCoreProtocol, -} from "./coreWebview.js"; -import { ToWebviewOrCoreFromIdeProtocol } from "./ide.js"; -import { ToCoreFromIdeProtocol, ToIdeFromCoreProtocol } from "./ideCore.js"; +} from "./coreWebview"; +import { ToWebviewOrCoreFromIdeProtocol } from "./ide"; +import { ToCoreFromIdeProtocol, ToIdeFromCoreProtocol } from "./ideCore"; import { ToIdeFromWebviewProtocol, ToWebviewFromIdeProtocol, -} from "./ideWebview.js"; +} from "./ideWebview"; export type IProtocol = Record; diff --git a/gui/src/components/markdown/CodeBlockToolbar.tsx b/gui/src/components/markdown/CodeBlockToolbar.tsx index ac4c03bb2..74c8f46c0 100644 --- a/gui/src/components/markdown/CodeBlockToolbar.tsx +++ b/gui/src/components/markdown/CodeBlockToolbar.tsx @@ -5,6 +5,7 @@ import { CommandLineIcon, PlayIcon, XMarkIcon, + ChevronDownIcon, } from "@heroicons/react/24/outline"; import { getBasename } from "core/util"; import { useContext, useRef, useState } from "react"; @@ -87,6 +88,8 @@ interface CodeBlockToolBarProps { language: string | undefined; isNextCodeBlock: boolean; filepath?: string; + isExpanded: boolean; + onToggleExpand: () => void; } const terminalLanguages = ["bash", "sh"]; @@ -260,12 +263,27 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) { return ( -
- - {getBasename(props.filepath)} +
+
+ +
+ + {props.filepath && ( +
+ + {getBasename(props.filepath)} +
+ )}
diff --git a/gui/src/components/markdown/PreWithToolbar.tsx b/gui/src/components/markdown/PreWithToolbar.tsx index ec9297d54..2f592ea9e 100644 --- a/gui/src/components/markdown/PreWithToolbar.tsx +++ b/gui/src/components/markdown/PreWithToolbar.tsx @@ -42,6 +42,7 @@ function PreWithToolbar(props: { const [hovering, setHovering] = useState(false); const [copyValue, setCopyValue] = useState(""); + const [isExpanded, setIsExpanded] = useState(false); const nextCodeBlockIndex = useSelector( (state: RootState) => state.uiState.nextCodeBlockToApplyIndex, @@ -76,6 +77,8 @@ function PreWithToolbar(props: { bottom={toolbarBottom} language={props.language} filepath={props.filepath} + isExpanded={isExpanded} + onToggleExpand={() => setIsExpanded(!isExpanded)} /> ) : ( hovering && ( @@ -84,11 +87,19 @@ function PreWithToolbar(props: { text={copyValue} bottom={toolbarBottom} language={props.language} + isExpanded={isExpanded} + onToggleExpand={() => setIsExpanded(!isExpanded)} /> ) )} - {props.children} +
+ {props.children} +
); }