From c35dacf64c45c34becffb9c59436091095c24a26 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Thu, 5 Feb 2026 00:05:37 +0800 Subject: [PATCH] feat: resolve the codeblock overflow issue --- src/components/steps/code-block.tsx | 80 +++++++++------------- src/components/steps/step-detail-panel.tsx | 24 +++---- src/components/ui/scroll-area.tsx | 1 + 3 files changed, 43 insertions(+), 62 deletions(-) diff --git a/src/components/steps/code-block.tsx b/src/components/steps/code-block.tsx index cb83986..62b9d69 100644 --- a/src/components/steps/code-block.tsx +++ b/src/components/steps/code-block.tsx @@ -6,13 +6,11 @@ import { Button } from '@/components/ui/button'; interface CodeBlockProps { code: string; - type: 'bash' | 'sql' | 'text'; + type: 'bash' | 'sql' | 'text' | 'branch'; showLineNumbers?: boolean; } export function CodeBlock({ code, type, showLineNumbers = true }: CodeBlockProps) { - console.log('[CodeBlock] Render - code length:', code?.length, 'code preview:', code?.substring(0, 50), 'type:', type); - const [copied, setCopied] = useState(false); // Compute highlighted code synchronously @@ -30,17 +28,14 @@ export function CodeBlock({ code, type, showLineNumbers = true }: CodeBlockProps require('prismjs/components/prism-bash'); } - const language = type === 'text' ? 'text' : type; + const language = type === 'text' || type === 'branch' ? 'text' : type; const grammar = Prism.languages[language] || Prism.languages.text; return Prism.highlight(code, grammar, language); } catch (e) { - console.error('[CodeBlock] Prism error:', e); return code.replace(//g, '>'); } }, [code, type]); - console.log('[CodeBlock] highlighted length:', highlighted?.length); - const handleCopy = async () => { await navigator.clipboard.writeText(code); setCopied(true); @@ -52,48 +47,37 @@ export function CodeBlock({ code, type, showLineNumbers = true }: CodeBlockProps const highlightedLines = highlighted ? highlighted.split('\n') : []; return ( -
- -
-
-          {showLineNumbers ? (
-            
- {/* Line numbers column */} -
- {lines.map((_: string, i: number) => ( - {i + 1} - ))} -
- {/* Code column */} -
- {highlightedLines.map((line: string, i: number) => ( - - ))} -
+
+
+        {showLineNumbers ? (
+          
+ {/* Line numbers column - fixed width */} +
+ {lines.map((_: string, i: number) => ( + {i + 1} + ))}
- ) : ( - - )} -
-
+ {/* Code column */} +
+ {highlightedLines.map((line: string, i: number) => ( + + ))} +
+
+ ) : ( + + )} +
); } diff --git a/src/components/steps/step-detail-panel.tsx b/src/components/steps/step-detail-panel.tsx index 5ae898c..b2985d9 100644 --- a/src/components/steps/step-detail-panel.tsx +++ b/src/components/steps/step-detail-panel.tsx @@ -73,13 +73,7 @@ export function StepDetailPanel({ // Sync state when step changes useEffect(() => { - console.log('[StepDetailPanel] useEffect triggered, step?.id:', step?.id); if (step) { - console.log('[StepDetailPanel] Syncing state with step:', { - stepId: step.id, - stepName: step.name, - stepContent: step.content?.substring(0, 50), - }); setNotes(step.notes || ''); setEditContent(step.content || ''); setIsEditing(false); @@ -89,8 +83,6 @@ export function StepDetailPanel({ } }, [step?.id]); - console.log('[StepDetailPanel] Render - step:', step?.id, 'step.content:', step?.content?.substring(0, 50), 'editContent:', editContent?.substring(0, 50)); - if (!step) return null; const isCustom = step.isCustom; @@ -189,7 +181,7 @@ export function StepDetailPanel({ return ( - +
@@ -205,8 +197,9 @@ export function StepDetailPanel({
- -
+
+ +
{/* Status & Type */}
@@ -226,7 +219,7 @@ export function StepDetailPanel({
{/* Content */} -
+
{!isEditing && ( @@ -263,7 +256,9 @@ export function StepDetailPanel({
) : ( - +
+ +
)} {/* Show original content if overridden */} @@ -375,7 +370,8 @@ export function StepDetailPanel({ )}
- + +
); diff --git a/src/components/ui/scroll-area.tsx b/src/components/ui/scroll-area.tsx index 8e4fa13..0c7be5f 100644 --- a/src/components/ui/scroll-area.tsx +++ b/src/components/ui/scroll-area.tsx @@ -19,6 +19,7 @@ function ScrollArea({ {children}