Skip to content

Commit 1321f93

Browse files
committed
Merge tag '0.31.2' into develop
2 parents 014023a + 205bbd0 commit 1321f93

17 files changed

Lines changed: 159 additions & 62 deletions

File tree

Core/Sources/ChatGPTChatTab/Chat.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,13 @@ struct Chat: ReducerProtocol {
226226
cancellable.cancel()
227227
}
228228
}
229-
for await _ in stream {
229+
let debouncedHistoryChange = TimedDebounceFunction(duration: 0.2) {
230230
await send(.historyChanged)
231231
}
232+
233+
for await _ in stream {
234+
await debouncedHistoryChange()
235+
}
232236
}.cancellable(id: CancelID.observeHistoryChange(id), cancelInFlight: true)
233237

234238
case .observeIsReceivingMessageChange:
@@ -450,3 +454,33 @@ struct ChatMenu: ReducerProtocol {
450454
}
451455
}
452456

457+
private actor TimedDebounceFunction {
458+
let duration: TimeInterval
459+
let block: () async -> Void
460+
461+
var task: Task<Void, Error>?
462+
var lastFireTime: Date = .init(timeIntervalSince1970: 0)
463+
464+
init(duration: TimeInterval, block: @escaping () async -> Void) {
465+
self.duration = duration
466+
self.block = block
467+
}
468+
469+
func callAsFunction() async {
470+
task?.cancel()
471+
if lastFireTime.timeIntervalSinceNow < -duration {
472+
await fire()
473+
task = nil
474+
} else {
475+
task = Task.detached { [weak self, duration] in
476+
try await Task.sleep(nanoseconds: UInt64(duration * 1_000_000_000))
477+
await self?.fire()
478+
}
479+
}
480+
}
481+
482+
func fire() async {
483+
lastFireTime = Date()
484+
await block()
485+
}
486+
}

Core/Sources/ChatGPTChatTab/ChatPanel.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct ChatPanel: View {
1818
Divider()
1919
ChatPanelInputArea(chat: chat)
2020
}
21-
.background(.regularMaterial)
21+
.background(.clear)
2222
.onAppear { chat.send(.appear) }
2323
}
2424
}
@@ -86,13 +86,23 @@ struct ChatPanelMessages: View {
8686
}
8787
.modify { view in
8888
if #available(macOS 13.0, *) {
89-
view.listRowSeparator(.hidden).listSectionSeparator(.hidden)
89+
view
90+
.listRowSeparator(.hidden)
91+
.listSectionSeparator(.hidden)
9092
} else {
9193
view
9294
}
9395
}
9496
}
9597
.listStyle(.plain)
98+
.listRowBackground(EmptyView())
99+
.modify { view in
100+
if #available(macOS 13.0, *) {
101+
view.scrollContentBackground(.hidden)
102+
} else {
103+
view
104+
}
105+
}
96106
.coordinateSpace(name: scrollSpace)
97107
.preference(
98108
key: ListHeightPreferenceKey.self,
@@ -218,7 +228,10 @@ struct ChatPanelMessages: View {
218228
if isInitialLoad {
219229
isInitialLoad = false
220230
}
221-
scrollToBottom()
231+
Task {
232+
await Task.yield()
233+
scrollToBottom()
234+
}
222235
}
223236
}
224237
}

Core/Sources/ChatGPTChatTab/Styles.swift

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extension Color {
99
if appearance.isDarkMode {
1010
return #colorLiteral(red: 0.1580096483, green: 0.1730263829, blue: 0.2026666105, alpha: 1)
1111
}
12-
return .white
12+
return #colorLiteral(red: 0.9896564803, green: 0.9896564803, blue: 0.9896564803, alpha: 1)
1313
}))
1414
}
1515

@@ -18,7 +18,7 @@ extension Color {
1818
if appearance.isDarkMode {
1919
return #colorLiteral(red: 0.2284317913, green: 0.2145925438, blue: 0.3214019983, alpha: 1)
2020
}
21-
return #colorLiteral(red: 0.896820749, green: 0.8709097223, blue: 0.9766687925, alpha: 1)
21+
return #colorLiteral(red: 0.9458052187, green: 0.9311983998, blue: 0.9906365955, alpha: 1)
2222
}))
2323
}
2424
}
@@ -92,6 +92,60 @@ extension MarkdownUI.Theme {
9292
}
9393
}
9494

95+
static func instruction(fontSize: Double) -> MarkdownUI.Theme {
96+
.gitHub.text {
97+
ForegroundColor(.primary)
98+
BackgroundColor(Color.clear)
99+
FontSize(fontSize)
100+
}
101+
.code {
102+
FontFamilyVariant(.monospaced)
103+
FontSize(.em(0.85))
104+
BackgroundColor(Color.secondary.opacity(0.2))
105+
}
106+
.codeBlock { configuration in
107+
let wrapCode = UserDefaults.shared.value(for: \.wrapCodeInChatCodeBlock)
108+
109+
if wrapCode {
110+
configuration.label
111+
.codeBlockLabelStyle()
112+
.codeBlockStyle(configuration)
113+
} else {
114+
ScrollView(.horizontal) {
115+
configuration.label
116+
.codeBlockLabelStyle()
117+
}
118+
.workaroundForVerticalScrollingBugInMacOS()
119+
.codeBlockStyle(configuration)
120+
}
121+
}
122+
.table { configuration in
123+
configuration.label
124+
.fixedSize(horizontal: false, vertical: true)
125+
.markdownTableBorderStyle(.init(
126+
color: .init(nsColor: .separatorColor),
127+
strokeStyle: .init(lineWidth: 1)
128+
))
129+
.markdownTableBackgroundStyle(
130+
.alternatingRows(Color.secondary.opacity(0.1), Color.secondary.opacity(0.2))
131+
)
132+
.markdownMargin(top: 0, bottom: 16)
133+
}
134+
.tableCell { configuration in
135+
configuration.label
136+
.markdownTextStyle {
137+
if configuration.row == 0 {
138+
FontWeight(.semibold)
139+
}
140+
BackgroundColor(nil)
141+
}
142+
.fixedSize(horizontal: false, vertical: true)
143+
.padding(.vertical, 6)
144+
.padding(.horizontal, 13)
145+
.relativeLineSpacing(.em(0.25))
146+
}
147+
}
148+
95149
static func functionCall(fontSize: Double) -> MarkdownUI.Theme {
96150
.gitHub.text {
97151
ForegroundColor(.secondary)

Core/Sources/ChatGPTChatTab/Views/BotMessage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct BotMessage: View {
6666
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
6767
}
6868
.padding(.leading, 8)
69-
.shadow(color: .black.opacity(0.1), radius: 2)
69+
.shadow(color: .black.opacity(0.05), radius: 6)
7070
.contextMenu {
7171
Button("Copy") {
7272
NSPasteboard.general.clearContents()

Core/Sources/ChatGPTChatTab/Views/Instructions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct Instruction: View {
7171
func body(content: Content) -> some View {
7272
content
7373
.textSelection(.enabled)
74-
.markdownTheme(.custom(fontSize: chatFontSize))
74+
.markdownTheme(.instruction(fontSize: chatFontSize))
7575
.opacity(0.8)
7676
.frame(maxWidth: .infinity, alignment: .leading)
7777
.padding()

Core/Sources/ChatGPTChatTab/Views/UserMessage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct UserMessage: View {
3434
}
3535
.padding(.leading)
3636
.padding(.trailing, 8)
37-
.shadow(color: .black.opacity(0.1), radius: 2)
37+
.shadow(color: .black.opacity(0.05), radius: 6)
3838
.frame(maxWidth: .infinity, alignment: .trailing)
3939
.contextMenu {
4040
Button("Copy") {

Core/Sources/HostApp/DebugView.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ final class DebugSettings: ObservableObject {
2525
var restartXcodeInspectorIfAccessibilityAPIIsMalfunctioningNoTimer
2626
@AppStorage(\.toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted)
2727
var toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted
28-
@AppStorage(\.observeToAXNotificationOnAnotherThread)
29-
var observeToAXNotificationOnAnotherThread
3028
@AppStorage(\.observeToAXNotificationWithDefaultMode)
3129
var observeToAXNotificationWithDefaultMode
3230
init() {}
@@ -120,14 +118,8 @@ struct DebugSettingsView: View {
120118
UserDefaults.shared.set(nil, forKey: "ChatModels")
121119
UserDefaults.shared.set(nil, forKey: "EmbeddingModels")
122120
}
123-
124-
Group {
125-
Toggle(
126-
isOn: $settings.observeToAXNotificationOnAnotherThread
127-
) {
128-
Text("Observe to AXNotification on background thread")
129-
}
130121

122+
Group {
131123
Toggle(
132124
isOn: $settings.observeToAXNotificationWithDefaultMode
133125
) {
@@ -136,6 +128,7 @@ struct DebugSettingsView: View {
136128
}
137129
}
138130
}
131+
.frame(maxWidth: .infinity)
139132
.padding()
140133
}
141134
}

Core/Sources/HostApp/FeatureSettings/ChatSettingsView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ struct ChatSettingsView: View {
313313
"Preferred Chat Model",
314314
selection: $settings.preferredChatModelIdForSenseScope
315315
) {
316-
Text("None").tag("")
316+
Text("Use the default model").tag("")
317317

318318
if !settings.chatModels
319319
.contains(where: {
@@ -364,7 +364,7 @@ struct ChatSettingsView: View {
364364
"Preferred Chat Model",
365365
selection: $settings.preferredChatModelIdForProjectScope
366366
) {
367-
Text("None").tag("")
367+
Text("Use the default model").tag("")
368368

369369
if !settings.chatModels
370370
.contains(where: {
@@ -390,7 +390,7 @@ struct ChatSettingsView: View {
390390

391391
SubSection(
392392
title: Text("Web Scope"),
393-
description: "Allow the bot to search on Bing or read a web page."
393+
description: "Allow the bot to search on Bing or read a web page. The current implementation requires function calling."
394394
) {
395395
Form {
396396
Toggle(isOn: $settings.enableWebScopeByDefaultInChatContext) {
@@ -401,7 +401,7 @@ struct ChatSettingsView: View {
401401
"Preferred Chat Model",
402402
selection: $settings.preferredChatModelIdForWebScope
403403
) {
404-
Text("None").tag("")
404+
Text("Use the default model").tag("")
405405

406406
if !settings.chatModels
407407
.contains(where: {

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct ChatWindowView: View {
4343
}
4444
.xcodeStyleFrame(cornerRadius: 10)
4545
.ignoresSafeArea(edges: .top)
46-
.background(.regularMaterial)
4746
.onChange(of: viewStore.state.isPanelDisplayed) { isDisplayed in
4847
toggleVisibility(isDisplayed)
4948
}

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public struct PromptToCode: ReducerProtocol {
187187
generateDescriptionRequirement: copiedState
188188
.generateDescriptionRequirement
189189
)
190+
#warning("TODO: make the action call debounced.")
190191
for try await fragment in stream {
191192
try Task.checkCancellation()
192193
await send(.modifyCodeChunkReceived(

0 commit comments

Comments
 (0)