Skip to content

Commit 8bd3b15

Browse files
committed
Add picker for presentation mode
1 parent f682d5c commit 8bd3b15

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

Copilot for Xcode/SettingsView.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ struct SettingsView: View {
99
var realtimeSuggestionToggle: Bool = false
1010
@AppStorage(SettingsKey.realtimeSuggestionDebounce, store: .shared)
1111
var realtimeSuggestionDebounce: Double = 0.7
12+
@AppStorage(SettingsKey.suggestionPresentationMode, store: .shared)
13+
var suggestionPresentationModeRawValue: Int = 0
1214
@State var editingRealtimeSuggestionDebounce: Double = UserDefaults.shared
1315
.value(forKey: SettingsKey.realtimeSuggestionDebounce) as? Double ?? 0.7
1416

@@ -19,6 +21,20 @@ struct SettingsView: View {
1921
Text("Quit service when Xcode and host app are terminated")
2022
}
2123
.toggleStyle(.switch)
24+
25+
Picker(selection: $suggestionPresentationModeRawValue) {
26+
ForEach(PresentationMode.allCases, id: \.rawValue) {
27+
switch $0 {
28+
case .comment:
29+
Text("Comment")
30+
case .floatingWidget:
31+
Text("Floating Widget")
32+
}
33+
}
34+
} label: {
35+
Text("Present suggestions in")
36+
}
37+
2238
Toggle(isOn: $realtimeSuggestionToggle) {
2339
Text("Real-time suggestion")
2440
}

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ public actor RealtimeSuggestionController {
6969
let isEditing = await Environment.frontmostXcodeWindowIsEditor()
7070

7171
// if Xcode suggestion panel is presenting, and we are not trying to close it
72-
// ignore this event.
72+
// ignore this event. (except present in window mode)
7373
if !isEditing, event.getIntegerValueField(.keyboardEventKeycode) != escape {
74-
return
74+
if UserDefaults.shared.integer(forKey: SettingsKey.suggestionPresentationMode) != 1 {
75+
return
76+
}
7577
}
7678

7779
let shouldTrigger = {
@@ -105,10 +107,14 @@ public actor RealtimeSuggestionController {
105107
.value(forKey: SettingsKey.realtimeSuggestionDebounce) as? Double
106108
?? 0.7
107109
) * 1_000_000_000))
110+
108111
guard UserDefaults.shared.bool(forKey: SettingsKey.realtimeSuggestionToggle)
109112
else { return }
113+
110114
if Task.isCancelled { return }
115+
111116
os_log(.info, "Prefetch suggestions.")
117+
112118
await realtimeSuggestionIndicatorController.triggerPrefetchAnimation()
113119
do {
114120
try await Environment.triggerAction("Prefetch Suggestions")

Core/Sources/Service/XPCService.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ public class XPCService: NSObject, XPCServiceProtocol {
108108
let task = Task {
109109
do {
110110
let editor = try JSONDecoder().decode(EditorContent.self, from: editorContent)
111-
let handler = WindowBaseCommandHandler()
111+
let mode = PresentationMode(
112+
rawValue: UserDefaults.shared
113+
.integer(forKey: SettingsKey.suggestionPresentationMode)
114+
) ?? .comment
115+
let handler: SuggestionCommandHanlder = {
116+
switch mode {
117+
case .comment:
118+
return CommentBaseCommandHandler()
119+
case .floatingWidget:
120+
return WindowBaseCommandHandler()
121+
}
122+
}()
112123
guard let updatedContent = try await getUpdatedContent(handler, editor) else {
113124
reply(nil, nil)
114125
return
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public enum PresentationMode: Int, CaseIterable {
2+
case comment = 0
3+
case floatingWidget = 1
4+
}

Core/Sources/XPCShared/UserDefaults.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public enum SettingsKey {
99
public static let realtimeSuggestionToggle = "RealtimeSuggestionToggle"
1010
public static let realtimeSuggestionDebounce = "RealtimeSuggestionDebounce"
1111
public static let quitXPCServiceOnXcodeAndAppQuit = "QuitXPCServiceOnXcodeAndAppQuit"
12+
public static let suggestionPresentationMode = "SuggestionPresentationMode"
1213
}

0 commit comments

Comments
 (0)