Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

Add syntax-highlighted code preview in agent steps, remove sidebar CodePreview

Abi Raja6001f696a96d
diff --git a/frontend/package.json b/frontend/package.json
index cbb7656f..29dd9ed1 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -31,6 +31,7 @@
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
+ "@types/react-syntax-highlighter": "^15.5.13",
"class-variance-authority": "^0.7.0",
"classnames": "^2.3.2",
"clsx": "^2.0.0",
@@ -45,6 +46,7 @@
"react-icons": "^4.12.0",
"react-markdown": "^10.1.0",
"react-router-dom": "^6.20.1",
+ "react-syntax-highlighter": "^16.1.0",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7",
"thememirror": "^2.0.1",
diff --git a/frontend/src/components/agent/AgentActivity.tsx b/frontend/src/components/agent/AgentActivity.tsx
index 372ec266..ab56495e 100644
--- a/frontend/src/components/agent/AgentActivity.tsx
+++ b/frontend/src/components/agent/AgentActivity.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { useProjectStore } from "../../store/project-store";
import { useAppStore } from "../../store/app-store";
import { AppState } from "../../types";
@@ -18,7 +18,35 @@ import {
BsFiles,
} from "react-icons/bs";
import ReactMarkdown from "react-markdown";
+import { Light as SyntaxHighlighterBase } from "react-syntax-highlighter";
+import html from "react-syntax-highlighter/dist/esm/languages/hljs/xml";
+import { vs2015 } from "react-syntax-highlighter/dist/esm/styles/hljs";
+SyntaxHighlighterBase.registerLanguage("html", html);
+const SyntaxHighlighter = SyntaxHighlighterBase as any;
+
+function CodePreviewBlock({ code, isGenerating }: { code: string; isGenerating: boolean }) {
+ const containerRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ if (isGenerating && containerRef.current) {
+ containerRef.current.scrollTop = containerRef.current.scrollHeight;
+ }
+ }, [code, isGenerating]);
+
+ return (
+ <div ref={containerRef} className="max-h-60 overflow-auto rounded-md">
+ <SyntaxHighlighter
+ language="html"
+ style={vs2015}
+ customStyle={{ margin: 0, padding: "0.5rem", fontSize: "0.75rem", borderRadius: "0.375rem" }}
+ wrapLongLines
+ >
+ {code}
+ </SyntaxHighlighter>
+ </div>
+ );
+}
function isFiniteNumber(value: unknown): value is number {
return typeof value === "number" && Number.isFinite(value);
@@ -162,9 +190,7 @@ function renderToolDetails(event: AgentEvent, variantCode?: string) {
</div>
)}
{event.toolName === "create_file" && !hasError && variantCode && (
- <pre className="rounded-md bg-gray-50 dark:bg-gray-800 p-2 text-xs text-gray-700 dark:text-gray-200 overflow-auto max-h-60 whitespace-pre-wrap break-all">
- {variantCode}
- </pre>
+ <CodePreviewBlock code={variantCode} isGenerating={event.status === "running"} />
)}
{event.toolName === "edit_file" && edits && !hasError && (
diff --git a/frontend/src/components/sidebar/Sidebar.tsx b/frontend/src/components/sidebar/Sidebar.tsx
index 96663c68..14b5684f 100644
--- a/frontend/src/components/sidebar/Sidebar.tsx
+++ b/frontend/src/components/sidebar/Sidebar.tsx
@@ -1,8 +1,6 @@
import { useAppStore } from "../../store/app-store";
import { useProjectStore } from "../../store/project-store";
import { AppState } from "../../types";
-import CodePreview from "../preview/CodePreview";
-// import TipLink from "../messages/TipLink";
import { Button } from "../ui/button";
import { useEffect, useRef, useState, useCallback } from "react";
import { LuMousePointerClick, LuRefreshCw, LuArrowUp } from "react-icons/lu";
@@ -63,10 +61,6 @@ function Sidebar({
const currentCommit = head ? commits[head] : null;
- const viewedCode = currentCommit
- ? currentCommit.variants[currentCommit.selectedVariantIndex].code
- : "";
-
const isFirstGeneration = currentCommit?.type === "ai_create";
// Check if the currently selected variant is complete
@@ -111,19 +105,15 @@ function Sidebar({
<div className="flex-1 min-h-0 overflow-y-auto sidebar-scrollbar-stable px-6 pt-4">
<AgentActivity />
- {/* Show code preview when coding and the selected variant is not complete */}
+ {/* Show cancel button when coding */}
{appState === AppState.CODING && !isSelectedVariantComplete && (
- <div className="flex flex-col">
- <CodePreview code={viewedCode} />
-
- <div className="flex w-full">
- <Button
- onClick={cancelCodeGeneration}
- className="w-full dark:text-white dark:bg-gray-700"
- >
- Cancel All Generations
- </Button>
- </div>
+ <div className="flex w-full">
+ <Button
+ onClick={cancelCodeGeneration}
+ className="w-full dark:text-white dark:bg-gray-700"
+ >
+ Cancel All Generations
+ </Button>
</div>
)}