mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Fix CodeBlock diffs
This commit is contained in:
@@ -78,7 +78,10 @@ const CodeBlock = ({ code, diff, language, path }: CodeBlockProps) => {
|
|||||||
*/
|
*/
|
||||||
const removeLeadingNonAlphanumeric = (path: string): string => path.replace(/^[^a-zA-Z0-9]+/, "")
|
const removeLeadingNonAlphanumeric = (path: string): string => path.replace(/^[^a-zA-Z0-9]+/, "")
|
||||||
|
|
||||||
const inferredLanguage = useMemo(() => language ?? (path ? getLanguageFromPath(path) : undefined), [path, language])
|
const inferredLanguage = useMemo(
|
||||||
|
() => code && (language ?? (path ? getLanguageFromPath(path) : undefined)),
|
||||||
|
[path, language, code]
|
||||||
|
)
|
||||||
|
|
||||||
console.log(inferredLanguage)
|
console.log(inferredLanguage)
|
||||||
|
|
||||||
@@ -86,7 +89,7 @@ const CodeBlock = ({ code, diff, language, path }: CodeBlockProps) => {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
borderRadius: "3px",
|
borderRadius: "3px",
|
||||||
marginRight: "2px",
|
marginRight: "2px",
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
overflow: "hidden", // This ensures the inner scrollable area doesn't overflow the rounded corners
|
overflow: "hidden", // This ensures the inner scrollable area doesn't overflow the rounded corners
|
||||||
}}>
|
}}>
|
||||||
@@ -126,29 +129,15 @@ const CodeBlock = ({ code, diff, language, path }: CodeBlockProps) => {
|
|||||||
}}>
|
}}>
|
||||||
<SyntaxHighlighter
|
<SyntaxHighlighter
|
||||||
wrapLines={false}
|
wrapLines={false}
|
||||||
language={inferredLanguage}
|
language={diff ? "diff" : inferredLanguage} // "diff" automatically colors changed lines in green/red
|
||||||
style={oneDark}
|
style={oneDark}
|
||||||
customStyle={{
|
customStyle={{
|
||||||
margin: 0,
|
margin: 0,
|
||||||
padding: "6px 10px",
|
padding: "6px 10px",
|
||||||
borderRadius: 0,
|
borderRadius: 0,
|
||||||
fontSize: 'var(--vscode-editor-font-size)',
|
fontSize: "var(--vscode-editor-font-size)",
|
||||||
lineHeight: 'var(--vscode-editor-line-height)'
|
lineHeight: "var(--vscode-editor-line-height)",
|
||||||
}}
|
}}>
|
||||||
lineProps={
|
|
||||||
diff != null
|
|
||||||
? (lineNumber) => {
|
|
||||||
const line = diff?.split("\n")?.[lineNumber - 1]
|
|
||||||
let style: React.CSSProperties = { display: "block", width: "100%" }
|
|
||||||
if (line && line[0] === "+") {
|
|
||||||
style.backgroundColor = "var(--vscode-diffEditor-insertedTextBackground)"
|
|
||||||
} else if (line && line[0] === "-") {
|
|
||||||
style.backgroundColor = "var(--vscode-diffEditor-removedTextBackground)"
|
|
||||||
}
|
|
||||||
return { style }
|
|
||||||
}
|
|
||||||
: undefined
|
|
||||||
}>
|
|
||||||
{code ?? diff ?? ""}
|
{code ?? diff ?? ""}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -126,25 +126,64 @@ export const mockMessages: ClaudeMessage[] = [
|
|||||||
text: JSON.stringify({
|
text: JSON.stringify({
|
||||||
tool: "editedExistingFile",
|
tool: "editedExistingFile",
|
||||||
path: "/src/components/TodoList.tsx",
|
path: "/src/components/TodoList.tsx",
|
||||||
diff: `@@ -14,6 +14,11 @@
|
diff: `+
|
||||||
}
|
+
|
||||||
};
|
import React, { useState } from "react"
|
||||||
|
|
||||||
+ const deleteTodo = (id: number) => {
|
interface Todo {
|
||||||
+ setTodos(todos.filter(todo => todo.id !== id));
|
id: number
|
||||||
+ };
|
text: string
|
||||||
+
|
completed: boolean
|
||||||
const toggleTodo = (id: number) => {
|
}
|
||||||
setTodos(todos.map(todo =>
|
|
||||||
todo.id === id ? { ...todo, completed: !todo.completed } : todo
|
const TodoList: React.FC = () => {
|
||||||
@@ -35,6 +40,7 @@
|
const [todos, setTodos] = useState<Todo[]>([])
|
||||||
style={{ textDecoration: todo.completed ? 'line-through' : 'none' }}
|
const [inputValue, setInputValue] = useState("")
|
||||||
>
|
|
||||||
{todo.text}
|
const addTodo = () => {
|
||||||
+ <button onClick={() => deleteTodo(todo.id)}>Delete</button>
|
if (inputValue.trim() !== "") {
|
||||||
</li>
|
setTodos([...todos, { id: Date.now(), text: inputValue, completed: false }])
|
||||||
))}
|
setInputValue("")
|
||||||
</ul>`,
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleTodo = (id: number) => {
|
||||||
|
setTodos(todos.map((todo) => (todo.id === id ? { ...todo, completed: !todo.completed } : todo)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Todo List</h1>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={inputValue}
|
||||||
|
onChange={(e) => setInputValue(e.target.value)}
|
||||||
|
placeholder="Add a new todo"
|
||||||
|
/>
|
||||||
|
|
||||||
|
- <button onClick={addTodo}>Add</button>
|
||||||
|
- <ul>
|
||||||
|
- {todos.map((todo) => (
|
||||||
|
- <li
|
||||||
|
- key={todo.id}
|
||||||
|
- onClick={() => toggleTodo(todo.id)}
|
||||||
|
- style={{ textDecoration: todo.completed ? "line-through" : "none" }}>
|
||||||
|
- {todo.text}
|
||||||
|
- </li>
|
||||||
|
- ))}
|
||||||
|
- </ul>
|
||||||
|
- </div>
|
||||||
|
-
|
||||||
|
+
|
||||||
|
+
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TodoList
|
||||||
|
|
||||||
|
+
|
||||||
|
+
|
||||||
|
`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user