55// Created by Tornike Gomareli on 18.06.25.
66//
77
8-
98import SwiftUI
109
1110/// View for rendering a single file's diff
1211struct DiffFileView : View {
1312 let file : DiffFile
14-
13+
1514 @Environment ( \. diffConfiguration) private var configuration
16-
15+
1716 var body : some View {
1817 VStack ( alignment: . leading, spacing: 0 ) {
1918 HStack {
2019 Image ( systemName: " doc.text " )
2120 . foregroundColor ( configuration. theme. fileHeaderText)
22-
21+
2322 Text ( file. displayName)
2423 . font ( . system( . headline, design: configuration. fontFamily) )
2524 . fontWeight ( . bold)
2625 . foregroundColor ( configuration. theme. fileHeaderText)
27-
26+
2827 Spacer ( )
29-
28+
3029 if file. isBinary {
3130 Text ( " Binary file " )
3231 . font ( . caption)
@@ -39,7 +38,7 @@ struct DiffFileView: View {
3938 }
4039 . padding ( )
4140 . background ( configuration. theme. fileHeaderBackground)
42-
41+
4342 if file. isBinary {
4443 Text ( " Binary file not shown " )
4544 . font ( . system( size: configuration. fontSize, design: configuration. fontFamily) )
@@ -55,7 +54,7 @@ struct DiffFileView: View {
5554 . padding ( . vertical, 4 )
5655 . frame ( maxWidth: . infinity, alignment: . leading)
5756 . background ( configuration. theme. headerBackground)
58-
57+
5958 VStack ( spacing: configuration. lineSpacing. value) {
6059 ForEach ( hunk. lines) { line in
6160 DiffLineView ( line: line)
@@ -86,24 +85,30 @@ struct DiffFileView: View {
8685 lines: [
8786 DiffLine ( type: . context, content: " import SwiftUI " , oldLineNumber: 1 , newLineNumber: 1 ) ,
8887 DiffLine ( type: . context, content: " " , oldLineNumber: 2 , newLineNumber: 2 ) ,
89- DiffLine ( type: . context, content: " struct ContentView: View { " , oldLineNumber: 3 , newLineNumber: 3 ) ,
90- DiffLine ( type: . added, content: " let title = \" Hello World \" " , oldLineNumber: nil , newLineNumber: 4 ) ,
91- DiffLine ( type: . context, content: " var body: some View { " , oldLineNumber: 4 , newLineNumber: 5 ) ,
92- DiffLine ( type: . removed, content: " Text( \" Hello, World! \" ) " , oldLineNumber: 5 , newLineNumber: nil ) ,
88+ DiffLine (
89+ type: . context, content: " struct ContentView: View { " , oldLineNumber: 3 , newLineNumber: 3 ) ,
90+ DiffLine (
91+ type: . added, content: " let title = \" Hello World \" " , oldLineNumber: nil ,
92+ newLineNumber: 4 ) ,
93+ DiffLine (
94+ type: . context, content: " var body: some View { " , oldLineNumber: 4 , newLineNumber: 5 ) ,
95+ DiffLine (
96+ type: . removed, content: " Text( \" Hello, World! \" ) " , oldLineNumber: 5 ,
97+ newLineNumber: nil ) ,
9398 DiffLine ( type: . added, content: " Text(title) " , oldLineNumber: nil , newLineNumber: 6 ) ,
94- DiffLine ( type: . added, content: " } " , oldLineNumber: nil , newLineNumber: 7 )
99+ DiffLine ( type: . added, content: " } " , oldLineNumber: nil , newLineNumber: 7 ) ,
95100 ]
96101 )
97-
102+
98103 let sampleFile = DiffFile (
99104 oldPath: " example.swift " ,
100105 newPath: " example.swift " ,
101106 hunks: [ sampleHunk] ,
102107 isBinary: false ,
103108 isRenamed: false
104109 )
105-
110+
106111 DiffFileView ( file: sampleFile)
107112 . padding ( )
108- . background ( Color ( UIColor . systemBackground) )
113+ . background ( Color ( . systemBackground) )
109114}
0 commit comments