MCPcopy Create free account
hub / github.com/winfunc/opcode / EditResultWidget

Function EditResultWidget

src/components/ToolWidgets.tsx:1205–1284  ·  view source on GitHub ↗
({ content })

Source from the content-addressed store, hash-verified

1203 * Widget for Edit tool result - shows a diff view
1204 */
1205export const EditResultWidget: React.FC<{ content: string }> = ({ content }) => {
1206 const { theme } = useTheme();
1207 const syntaxTheme = getClaudeSyntaxTheme(theme);
1208
1209 // Parse the content to extract file path and code snippet
1210 const lines = content.split('\n');
1211 let filePath = '';
1212 const codeLines: { lineNumber: string; code: string }[] = [];
1213 let inCodeBlock = false;
1214
1215 for (const rawLine of lines) {
1216 const line = rawLine.replace(/\r$/, '');
1217 if (line.includes('The file') && line.includes('has been updated')) {
1218 const match = line.match(/The file (.+) has been updated/);
1219 if (match) {
1220 filePath = match[1];
1221 }
1222 } else if (/^\s*\d+/.test(line)) {
1223 inCodeBlock = true;
1224 const lineMatch = line.match(/^\s*(\d+)\t?(.*)$/);
1225 if (lineMatch) {
1226 const [, lineNum, codePart] = lineMatch;
1227 codeLines.push({
1228 lineNumber: lineNum,
1229 code: codePart,
1230 });
1231 }
1232 } else if (inCodeBlock) {
1233 // Allow non-numbered lines inside a code block (for empty lines)
1234 codeLines.push({ lineNumber: '', code: line });
1235 }
1236 }
1237
1238 const codeContent = codeLines.map(l => l.code).join('\n');
1239 const firstNumberedLine = codeLines.find(l => l.lineNumber !== '');
1240 const startLineNumber = firstNumberedLine ? parseInt(firstNumberedLine.lineNumber) : 1;
1241 const language = getLanguage(filePath);
1242
1243 return (
1244 <div className="rounded-lg border bg-zinc-950 overflow-hidden">
1245 <div className="px-4 py-2 border-b bg-emerald-950/30 flex items-center gap-2">
1246 <GitBranch className="h-3.5 w-3.5 text-emerald-500" />
1247 <span className="text-xs font-mono text-emerald-400">Edit Result</span>
1248 {filePath && (
1249 <>
1250 <ChevronRight className="h-3 w-3 text-muted-foreground" />
1251 <span className="text-xs font-mono text-muted-foreground">{filePath}</span>
1252 </>
1253 )}
1254 </div>
1255 <div className="overflow-x-auto max-h-[440px]">
1256 <SyntaxHighlighter
1257 language={language}
1258 style={syntaxTheme}
1259 showLineNumbers
1260 startingLineNumber={startLineNumber}
1261 wrapLongLines={false}
1262 customStyle={{

Callers

nothing calls this directly

Calls 3

useThemeFunction · 0.90
getClaudeSyntaxThemeFunction · 0.90
getLanguageFunction · 0.85

Tested by

no test coverage detected