Skip to content

Commit ea5e7e3

Browse files
authored
Merge pull request #6467 from continuedev/nate/diff-ui-edit
don't expand edit tool codeblocks by default
2 parents dc0546d + 923b7e7 commit ea5e7e3

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { ChevronDownIcon } from "@heroicons/react/24/outline";
2+
import { useState } from "react";
3+
4+
interface CollapsibleContainerProps {
5+
children: React.ReactNode;
6+
maxHeight?: string;
7+
className?: string;
8+
collapsible?: boolean;
9+
}
10+
11+
export function CollapsibleContainer({
12+
children,
13+
maxHeight = "max-h-40",
14+
className = "",
15+
collapsible = false,
16+
}: CollapsibleContainerProps) {
17+
const [isExpanded, setIsExpanded] = useState(false);
18+
19+
// If not collapsible, just render children without any collapsible behavior
20+
if (!collapsible) {
21+
return <div className={className}>{children}</div>;
22+
}
23+
24+
return (
25+
<div className={`relative ${className}`}>
26+
<div className={`overflow-hidden ${isExpanded ? "" : maxHeight}`}>
27+
{children}
28+
</div>
29+
30+
{!isExpanded && (
31+
<div className="from-editor absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t to-transparent">
32+
<div
33+
onClick={() => setIsExpanded(true)}
34+
className="group flex h-full cursor-pointer items-end justify-center pb-2"
35+
>
36+
<span title="Expand to show full content">
37+
<ChevronDownIcon className="text-lightgray group-hover:text-foreground h-4 w-4" />
38+
</span>
39+
</div>
40+
</div>
41+
)}
42+
43+
{isExpanded && (
44+
<div
45+
onClick={() => setIsExpanded(false)}
46+
className="group mt-2 flex cursor-pointer justify-center"
47+
>
48+
<span title="Collapse to compact view">
49+
<ChevronDownIcon className="text-lightgray group-hover:text-foreground h-4 w-4 rotate-180" />
50+
</span>
51+
</div>
52+
)}
53+
</div>
54+
);
55+
}

gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getFontSize } from "../../../util";
1313
import Spinner from "../../gui/Spinner";
1414
import { isTerminalCodeBlock } from "../utils";
1515
import { ApplyActions } from "./ApplyActions";
16+
import { CollapsibleContainer } from "./CollapsibleContainer";
1617
import { CopyButton } from "./CopyButton";
1718
import { CreateFileButton } from "./CreateFileButton";
1819
import { FileInfo } from "./FileInfo";
@@ -32,6 +33,7 @@ export interface StepContainerPreToolbarProps {
3233
children: any;
3334
expanded?: boolean;
3435
disableManualApply?: boolean;
36+
collapsible?: boolean;
3537
}
3638

3739
export function StepContainerPreToolbar({
@@ -47,6 +49,7 @@ export function StepContainerPreToolbar({
4749
children,
4850
expanded,
4951
disableManualApply,
52+
collapsible,
5053
}: StepContainerPreToolbarProps) {
5154
const ideMessenger = useContext(IdeMessengerContext);
5255
const history = useAppSelector((state) => state.session.history);
@@ -298,9 +301,10 @@ export function StepContainerPreToolbar({
298301
{renderActionButtons()}
299302
</div>
300303
</div>
301-
302304
{isExpanded && (
303-
<div className="overflow-hidden overflow-y-auto">{children}</div>
305+
<CollapsibleContainer collapsible={collapsible}>
306+
{children}
307+
</CollapsibleContainer>
304308
)}
305309
</div>
306310
);

gui/src/components/StyledMarkdownPreview/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ interface StyledMarkdownPreviewProps {
127127
disableManualApply?: boolean;
128128
toolCallId?: string;
129129
expandCodeblocks?: boolean;
130+
collapsible?: boolean;
130131
}
131132

132133
const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-";
@@ -305,6 +306,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
305306
forceToolCallId={props.toolCallId}
306307
expanded={props.expandCodeblocks}
307308
disableManualApply={props.disableManualApply}
309+
collapsible={props.collapsible}
308310
>
309311
<SyntaxHighlightedPre {...preProps} />
310312
</StepContainerPreToolbar>

gui/src/pages/gui/ToolCallDiv/EditFile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ export function EditFile(props: EditToolCallProps) {
1818

1919
return (
2020
<StyledMarkdownPreview
21-
expandCodeblocks={props.expandCodeblocks ?? false}
21+
expandCodeblocks={false}
2222
isRenderingInStepContainer
2323
disableManualApply
2424
source={src}
2525
toolCallId={props.toolCallId}
2626
itemIndex={props.historyIndex}
27+
collapsible={true}
2728
/>
2829
);
2930
}

0 commit comments

Comments
 (0)