summaryrefslogtreecommitdiffhomepage
path: root/packages/web/src/components/DiffView.tsx
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-31 18:42:43 -0400
committerDax Raad <[email protected]>2025-05-31 18:42:43 -0400
commite97ed735d9b21a71db027d483a17d02c509a6090 (patch)
tree90e023bf2bd43cd06d22a94bd16d2c84ac8b840c /packages/web/src/components/DiffView.tsx
parent6d21525e717122f106c87821fc2aab9f7d2c3fe5 (diff)
downloadopencode-e97ed735d9b21a71db027d483a17d02c509a6090.tar.gz
opencode-e97ed735d9b21a71db027d483a17d02c509a6090.zip
sync
Diffstat (limited to 'packages/web/src/components/DiffView.tsx')
-rw-r--r--packages/web/src/components/DiffView.tsx24
1 files changed, 10 insertions, 14 deletions
diff --git a/packages/web/src/components/DiffView.tsx b/packages/web/src/components/DiffView.tsx
index 4e864e06b..6f89d6a97 100644
--- a/packages/web/src/components/DiffView.tsx
+++ b/packages/web/src/components/DiffView.tsx
@@ -1,5 +1,5 @@
-import { type Component, createSignal, onMount } from "solid-js"
-import { diffLines } from "diff"
+import { type Component, createMemo, createSignal, onMount } from "solid-js"
+import { diffLines, type ChangeObject } from "diff"
import CodeBlock from "./CodeBlock"
import styles from "./diffview.module.css"
@@ -10,33 +10,29 @@ type DiffRow = {
}
interface DiffViewProps {
- oldCode: string
- newCode: string
+ changes: ChangeObject<string>[]
lang?: string
class?: string
}
const DiffView: Component<DiffViewProps> = (props) => {
- const [rows, setRows] = createSignal<DiffRow[]>([])
-
- onMount(() => {
- const chunks = diffLines(props.oldCode, props.newCode)
+ const rows = createMemo(() => {
const diffRows: DiffRow[] = []
- for (const chunk of chunks) {
- const lines = chunk.value.split(/\r?\n/)
+ for (const item of props.changes) {
+ const lines = item.value.split(/\r?\n/)
if (lines.at(-1) === "") lines.pop()
for (const line of lines) {
diffRows.push({
- left: chunk.removed ? line : chunk.added ? "" : line,
- right: chunk.added ? line : chunk.removed ? "" : line,
- type: chunk.added ? "added" : chunk.removed ? "removed" : "unchanged",
+ left: item.removed ? line : item.added ? "" : line,
+ right: item.added ? line : item.removed ? "" : line,
+ type: item.added ? "added" : item.removed ? "removed" : "unchanged",
})
}
}
- setRows(diffRows)
+ return diffRows
})
return (