forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffView.swift
More file actions
96 lines (81 loc) · 2.49 KB
/
DiffView.swift
File metadata and controls
96 lines (81 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import SwiftUI
import WebKit
import ComposableArchitecture
import Logger
import ConversationServiceProvider
import ChatService
import ChatTab
extension FileEdit {
var originalContentByStatus: String {
return status == .kept ? modifiedContent : originalContent
}
var modifiedContentByStatus: String {
return status == .undone ? originalContent : modifiedContent
}
}
struct DiffView: View {
@Perception.Bindable var chat: StoreOf<Chat>
@State public var fileEdit: FileEdit
var body: some View {
WithPerceptionTracking {
DiffWebView(
chat: chat,
fileEdit: fileEdit
)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
}
}
}
// preview
struct DiffView_Previews: PreviewProvider {
static var oldText = """
import Foundation
func calculateTotal(items: [Double]) -> Double {
var sum = 0.0
for item in items {
sum += item
}
return sum
}
func main() {
let prices = [10.5, 20.0, 15.75]
let total = calculateTotal(items: prices)
print("Total: \\(total)")
}
main()
"""
static var newText = """
import Foundation
func calculateTotal(items: [Double], applyDiscount: Bool = false) -> Double {
var sum = 0.0
for item in items {
sum += item
}
// Apply 10% discount if requested
if applyDiscount {
sum *= 0.9
}
return sum
}
func main() {
let prices = [10.5, 20.0, 15.75, 5.0]
let total = calculateTotal(items: prices)
let discountedTotal = calculateTotal(items: prices, applyDiscount: true)
print("Total: \\(total)")
print("With discount: \\(discountedTotal)")
}
main()
"""
static let chatTabInfo = ChatTabInfo(id: "", workspacePath: "path", username: "name")
static var previews: some View {
DiffView(
chat: .init(
initialState: .init(history: ChatPanel_Preview.history, isReceivingMessage: true),
reducer: { Chat(service: ChatService.service(for: chatTabInfo)) }
),
fileEdit: .init(fileURL: URL(fileURLWithPath: "file:///f1.swift"), originalContent: "test", modifiedContent: "abc", toolName: ToolName.insertEditIntoFile)
)
.frame(width: 800, height: 600)
}
}