diff options
| author | Jay <[email protected]> | 2025-06-24 17:11:43 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-24 17:11:43 -0400 |
| commit | a2d3b9f0c83a8ef9ed88efab2703ae436eac71b6 (patch) | |
| tree | 46437c8f5f5d2ce3940f8186d9ac31d476b12932 /packages/web/src/components/DiffView.tsx | |
| parent | 9cfb6ff9646553d6dcbcbe22844ffbeb6480dc12 (diff) | |
| download | opencode-a2d3b9f0c83a8ef9ed88efab2703ae436eac71b6.tar.gz opencode-a2d3b9f0c83a8ef9ed88efab2703ae436eac71b6.zip | |
docs: Share page diff view improvements (#373)
Diffstat (limited to 'packages/web/src/components/DiffView.tsx')
| -rw-r--r-- | packages/web/src/components/DiffView.tsx | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/packages/web/src/components/DiffView.tsx b/packages/web/src/components/DiffView.tsx index a7464e2e6..237f25bdf 100644 --- a/packages/web/src/components/DiffView.tsx +++ b/packages/web/src/components/DiffView.tsx @@ -113,29 +113,83 @@ const DiffView: Component<DiffViewProps> = (props) => { return ( <div class={`${styles.diff} ${props.class ?? ""}`}> - <div class={styles.column}> - {rows().map((r) => ( - <CodeBlock - code={r.left} - lang={props.lang} - data-section="cell" - data-diff-type={r.type === "removed" || r.type === "modified" ? "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" || r.type === "modified" ? "added" : ""} - /> - ))} - </div> + {rows().map((r) => ( + <div class={styles.row}> + <div class={styles.beforeColumn}> + <CodeBlock + code={r.left} + lang={props.lang} + data-section="cell" + data-diff-type={r.type === "removed" || r.type === "modified" ? "removed" : ""} + data-display-mobile={r.type === "added" && !r.left ? "false" : undefined} + /> + {(r.type === "added" || r.type === "modified") && r.right !== undefined && ( + <CodeBlock + code={r.right} + lang={props.lang} + data-section="cell" + data-diff-type="added" + data-display-mobile="true" + /> + )} + </div> + + <div class={styles.afterColumn}> + <CodeBlock + code={r.right} + lang={props.lang} + data-section="cell" + data-diff-type={r.type === "added" || r.type === "modified" ? "added" : ""} + /> + </div> + </div> + ))} </div> ) } export default DiffView + +// String to test diff viewer with +const testDiff = `--- combined_before.txt 2025-06-24 16:38:08 ++++ combined_after.txt 2025-06-24 16:38:12 +@@ -1,21 +1,25 @@ + unchanged line +-deleted line +-old content ++added line ++new content + +-removed empty line below ++added empty line above + +- tab indented +-trailing spaces +-very long line that will definitely wrap in most editors and cause potential alignment issues when displayed in a two column diff view +-unicode content: π β¨ δΈζ +-mixed content with tabs and spaces ++ space indented ++no trailing spaces ++short line ++very long replacement line that will also wrap and test how the diff viewer handles long line additions after short line removals ++different unicode: π π» ζ₯ζ¬θͺ ++normalized content with consistent spacing ++newline to content + +-content to remove +-whitespace only: +-multiple +-consecutive +-deletions +-single deletion ++ ++single addition ++first addition ++second addition ++third addition + line before addition ++first added line ++ ++third added line + line after addition + final unchanged line` |
