summaryrefslogtreecommitdiffhomepage
path: root/app/packages/web/src/components/DiffView.tsx
diff options
context:
space:
mode:
authorJay V <[email protected]>2025-05-30 16:42:56 -0400
committerJay V <[email protected]>2025-05-30 16:42:59 -0400
commitc391c6d3f3ee4a041ab30f576aae0abfca8f7c9a (patch)
tree8fb6117f40892081dc892a37afad52434ae89811 /app/packages/web/src/components/DiffView.tsx
parentca562266b7ec8d21cc623b9625b4cc8bb8938195 (diff)
downloadopencode-c391c6d3f3ee4a041ab30f576aae0abfca8f7c9a.tar.gz
opencode-c391c6d3f3ee4a041ab30f576aae0abfca8f7c9a.zip
tweaking share edit
Diffstat (limited to 'app/packages/web/src/components/DiffView.tsx')
-rw-r--r--app/packages/web/src/components/DiffView.tsx29
1 files changed, 18 insertions, 11 deletions
diff --git a/app/packages/web/src/components/DiffView.tsx b/app/packages/web/src/components/DiffView.tsx
index 7b20f9d86..44feef140 100644
--- a/app/packages/web/src/components/DiffView.tsx
+++ b/app/packages/web/src/components/DiffView.tsx
@@ -1,5 +1,5 @@
import { type Component, createSignal, onMount } from "solid-js"
-import { diffLines, type Change } from "diff"
+import { diffLines } from "diff"
import CodeBlock from "./CodeBlock"
import styles from "./diffview.module.css"
@@ -23,42 +23,49 @@ const DiffView: Component<DiffViewProps> = (props) => {
const chunks = diffLines(props.oldCode, props.newCode)
const diffRows: DiffRow[] = []
- chunks.forEach((chunk: Change) => {
+ for (const chunk of chunks) {
const lines = chunk.value.split(/\r?\n/)
if (lines.at(-1) === "") lines.pop()
- lines.forEach((line) => {
+ 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"
+ type: chunk.added
+ ? "added"
+ : chunk.removed
+ ? "removed"
: "unchanged",
})
- })
- })
+ }
+ }
setRows(diffRows)
})
return (
<div class={`${styles.diff} ${props.class ?? ""}`}>
- {rows().map((r) => (
- <div data-section="row">
+ <div class={styles.column}>
+ {rows().map((r) => (
<CodeBlock
code={r.left}
lang={props.lang}
data-section="cell"
data-diff-type={r.type === "removed" ? "removed" : ""}
/>
+ ))}
+ </div>
+
+ <div class={styles.column}>
+ {rows().map((r) => (
<CodeBlock
code={r.right}
lang={props.lang}
data-section="cell"
data-diff-type={r.type === "added" ? "added" : ""}
/>
- </div>
- ))}
+ ))}
+ </div>
</div>
)
}