Skip to content

Commit 7616a24

Browse files
committed
Merge branch 'release/0.8.6'
2 parents 6798594 + 0c6098d commit 7616a24

File tree

9 files changed

+309
-84
lines changed

9 files changed

+309
-84
lines changed

Copilot for Xcode/ContentView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ struct ContentView: View {
2626
startPoint: .topLeading,
2727
endPoint: .bottom
2828
))
29+
.overlay(alignment: .top) {
30+
LinearGradient(
31+
colors: [Color("BackgroundColorTop"), Color("BackgroundColorTop").opacity(0)],
32+
startPoint: .center,
33+
endPoint: .bottom
34+
)
35+
.frame(height: 44)
36+
.ignoresSafeArea()
37+
}
2938
}
3039
}
3140

Copilot for Xcode/SettingsView.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ final class Settings: ObservableObject {
1515
var automaticallyCheckForUpdate: Bool = false
1616
@AppStorage(SettingsKey.suggestionWidgetPositionMode, store: .shared)
1717
var suggestionWidgetPositionModeRawValue: Int = 0
18+
@AppStorage(SettingsKey.widgetColorScheme, store: .shared)
19+
var widgetColorScheme: Int = 0
1820
init() {}
1921
}
2022

@@ -64,6 +66,21 @@ struct SettingsView: View {
6466
} label: {
6567
Text("Widget position")
6668
}
69+
70+
Picker(selection: $settings.widgetColorScheme) {
71+
ForEach(WidgetColorScheme.allCases, id: \.rawValue) {
72+
switch $0 {
73+
case .system:
74+
Text("System")
75+
case .light:
76+
Text("Light")
77+
case .dark:
78+
Text("Dark")
79+
}
80+
}
81+
} label: {
82+
Text("Widget color scheme")
83+
}
6784
}
6885

6986
Toggle(isOn: $settings.realtimeSuggestionToggle) {

Core/Sources/SuggestionWidget/SuggestionPanelView.swift

Lines changed: 121 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Environment
21
import SwiftUI
32

43
@MainActor
@@ -20,6 +19,7 @@ final class SuggestionPanelViewModel: ObservableObject {
2019
@Published var suggestion: Suggestion
2120
@Published var isPanelDisplayed: Bool
2221
@Published var alignTopToAnchor = false
22+
@Published var colorScheme: ColorScheme
2323

2424
var onAcceptButtonTapped: (() -> Void)?
2525
var onRejectButtonTapped: (() -> Void)?
@@ -29,13 +29,15 @@ final class SuggestionPanelViewModel: ObservableObject {
2929
public init(
3030
suggestion: Suggestion = .empty,
3131
isPanelDisplayed: Bool = false,
32+
colorScheme: ColorScheme = .dark,
3233
onAcceptButtonTapped: (() -> Void)? = nil,
3334
onRejectButtonTapped: (() -> Void)? = nil,
3435
onPreviousButtonTapped: (() -> Void)? = nil,
3536
onNextButtonTapped: (() -> Void)? = nil
3637
) {
3738
self.suggestion = suggestion
3839
self.isPanelDisplayed = isPanelDisplayed
40+
self.colorScheme = colorScheme
3941
self.onAcceptButtonTapped = onAcceptButtonTapped
4042
self.onRejectButtonTapped = onRejectButtonTapped
4143
self.onPreviousButtonTapped = onPreviousButtonTapped
@@ -45,8 +47,6 @@ final class SuggestionPanelViewModel: ObservableObject {
4547

4648
struct SuggestionPanelView: View {
4749
@ObservedObject var viewModel: SuggestionPanelViewModel
48-
@State var codeHeight: Double = 0
49-
let backgroundColor = #colorLiteral(red: 0.1580096483, green: 0.1730263829, blue: 0.2026666105, alpha: 1)
5050

5151
var body: some View {
5252
VStack {
@@ -60,8 +60,18 @@ struct SuggestionPanelView: View {
6060
VStack(spacing: 0) {
6161
ScrollView {
6262
CodeBlock(viewModel: viewModel)
63+
.frame(maxWidth: .infinity)
6364
}
64-
.background(Color(nsColor: backgroundColor))
65+
.background(Color(nsColor: {
66+
switch viewModel.colorScheme {
67+
case .dark:
68+
return #colorLiteral(red: 0.1580096483, green: 0.1730263829, blue: 0.2026666105, alpha: 1)
69+
case .light:
70+
return .white
71+
@unknown default:
72+
return .white
73+
}
74+
}()))
6575

6676
ToolBar(viewModel: viewModel)
6777
}
@@ -79,7 +89,7 @@ struct SuggestionPanelView: View {
7989
.padding(1)
8090
)
8191
.allowsHitTesting(viewModel.isPanelDisplayed && !viewModel.suggestion.code.isEmpty)
82-
.preferredColorScheme(.dark)
92+
.preferredColorScheme(viewModel.colorScheme)
8393

8494
if viewModel.alignTopToAnchor {
8595
Spacer()
@@ -106,7 +116,7 @@ struct CodeBlock: View {
106116
HStack(alignment: .firstTextBaseline) {
107117
Text("\(index + viewModel.suggestion.startLineIndex + 1)")
108118
.multilineTextAlignment(.trailing)
109-
.foregroundColor(Color.white.opacity(0.6))
119+
.foregroundColor(.secondary)
110120
.frame(minWidth: 40)
111121
Text(AttributedString(viewModel.suggestion.code[index]))
112122
.foregroundColor(.white.opacity(0.1))
@@ -128,13 +138,7 @@ struct ToolBar: View {
128138
var body: some View {
129139
HStack {
130140
Button(action: {
131-
Task {
132-
if let block = viewModel.onPreviousButtonTapped {
133-
block()
134-
return
135-
}
136-
try await Environment.triggerAction("Previous Suggestion")
137-
}
141+
viewModel.onPreviousButtonTapped?()
138142
}) {
139143
Image(systemName: "chevron.left")
140144
}.buttonStyle(.plain)
@@ -145,39 +149,21 @@ struct ToolBar: View {
145149
.monospacedDigit()
146150

147151
Button(action: {
148-
Task {
149-
if let block = viewModel.onNextButtonTapped {
150-
block()
151-
return
152-
}
153-
try await Environment.triggerAction("Next Suggestion")
154-
}
152+
viewModel.onNextButtonTapped?()
155153
}) {
156154
Image(systemName: "chevron.right")
157155
}.buttonStyle(.plain)
158156

159157
Spacer()
160158

161159
Button(action: {
162-
Task {
163-
if let block = viewModel.onRejectButtonTapped {
164-
block()
165-
return
166-
}
167-
try await Environment.triggerAction("Reject Suggestion")
168-
}
160+
viewModel.onRejectButtonTapped?()
169161
}) {
170162
Text("Reject")
171163
}.buttonStyle(CommandButtonStyle(color: .gray))
172164

173165
Button(action: {
174-
Task {
175-
if let block = viewModel.onAcceptButtonTapped {
176-
block()
177-
return
178-
}
179-
try await Environment.triggerAction("Accept Suggestion")
180-
}
166+
viewModel.onAcceptButtonTapped?()
181167
}) {
182168
Text("Accept")
183169
}.buttonStyle(CommandButtonStyle(color: .indigo))
@@ -208,7 +194,7 @@ struct CommandButtonStyle: ButtonStyle {
208194
}
209195
}
210196

211-
struct SuggestionPanelView_Preview: PreviewProvider {
197+
struct SuggestionPanelView_Dark_Preview: PreviewProvider {
212198
static var previews: some View {
213199
SuggestionPanelView(viewModel: .init(
214200
suggestion: .init(
@@ -222,12 +208,110 @@ struct SuggestionPanelView_Preview: PreviewProvider {
222208
.multilineTextAlignment(.leading)
223209
}
224210
""",
225-
language: "swift"
211+
language: "swift",
212+
brightMode: false
213+
),
214+
suggestionCount: 2,
215+
currentSuggestionIndex: 0
216+
),
217+
isPanelDisplayed: true,
218+
colorScheme: .dark
219+
))
220+
.frame(width: 450, height: 400)
221+
.background {
222+
HStack {
223+
Color.red
224+
Color.green
225+
Color.blue
226+
}
227+
}
228+
}
229+
}
230+
231+
struct SuggestionPanelView_Bright_Preview: PreviewProvider {
232+
static var previews: some View {
233+
SuggestionPanelView(viewModel: .init(
234+
suggestion: .init(
235+
startLineIndex: 8,
236+
code: highlighted(
237+
code: """
238+
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
239+
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
240+
Text(viewModel.suggestion[index])
241+
.frame(maxWidth: .infinity, alignment: .leading)
242+
.multilineTextAlignment(.leading)
243+
}
244+
""",
245+
language: "swift",
246+
brightMode: true
247+
),
248+
suggestionCount: 2,
249+
currentSuggestionIndex: 0
250+
),
251+
isPanelDisplayed: true,
252+
colorScheme: .light
253+
))
254+
.frame(width: 450, height: 400)
255+
.background {
256+
HStack {
257+
Color.red
258+
Color.green
259+
Color.blue
260+
}
261+
}
262+
}
263+
}
264+
265+
struct SuggestionPanelView_Dark_Objc_Preview: PreviewProvider {
266+
static var previews: some View {
267+
SuggestionPanelView(viewModel: .init(
268+
suggestion: .init(
269+
startLineIndex: 8,
270+
code: highlighted(
271+
code: """
272+
- (void)addSubview:(UIView *)view {
273+
[self addSubview:view];
274+
}
275+
""",
276+
language: "objective-c",
277+
brightMode: false
278+
),
279+
suggestionCount: 2,
280+
currentSuggestionIndex: 0
281+
),
282+
isPanelDisplayed: true,
283+
colorScheme: .dark
284+
))
285+
.frame(width: 450, height: 400)
286+
.background {
287+
HStack {
288+
Color.red
289+
Color.green
290+
Color.blue
291+
}
292+
}
293+
}
294+
}
295+
296+
struct SuggestionPanelView_Bright_Objc_Preview: PreviewProvider {
297+
static var previews: some View {
298+
SuggestionPanelView(viewModel: .init(
299+
suggestion: .init(
300+
startLineIndex: 8,
301+
code: highlighted(
302+
code: """
303+
- (void)addSubview:(UIView *)view {
304+
[self addSubview:view];
305+
}
306+
""",
307+
language: "objective-c",
308+
brightMode: true
226309
),
227310
suggestionCount: 2,
228311
currentSuggestionIndex: 0
229312
),
230-
isPanelDisplayed: true
313+
isPanelDisplayed: true,
314+
colorScheme: .light
231315
))
232316
.frame(width: 450, height: 400)
233317
.background {

0 commit comments

Comments
 (0)