Skip to content

Commit 0e06566

Browse files
committed
Merge branch 'feature/accept-suggestion-auto-fallback' into develop
2 parents ce9ec00 + f26c64f commit 0e06566

6 files changed

Lines changed: 23 additions & 53 deletions

File tree

Core/Sources/Environment/Environment.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public enum Environment {
163163
Logger.service
164164
.error("Trigger command \(name) failed: \(error.localizedDescription)")
165165
throw error
166+
} else {
167+
return
166168
}
167169
}
168170
} else if let commandMenu = app.menuBar?.child(title: bundleName),
@@ -173,17 +175,18 @@ public enum Environment {
173175
Logger.service
174176
.error("Trigger command \(name) failed: \(error.localizedDescription)")
175177
throw error
178+
} else {
179+
return
176180
}
177-
} else {
178-
struct CantRunCommand: Error, LocalizedError {
179-
let name: String
180-
var errorDescription: String? {
181-
"Can't run command \(name)."
182-
}
181+
}
182+
struct CantRunCommand: Error, LocalizedError {
183+
let name: String
184+
var errorDescription: String? {
185+
"Can't run command \(name)."
183186
}
184-
185-
throw CantRunCommand(name: name)
186187
}
188+
189+
throw CantRunCommand(name: name)
187190
} else {
188191
/// check if menu is open, if not, click the menu item.
189192
let appleScript = """

Core/Sources/HostApp/FeatureSettings/PromptToCodeSettingsView.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct PromptToCodeSettingsView: View {
66
var hideCommonPrecedingSpacesInSuggestion
77
@AppStorage(\.suggestionCodeFontSize)
88
var suggestionCodeFontSize
9-
@AppStorage(\.acceptSuggestionWithAccessibilityAPI)
10-
var acceptSuggestionWithAccessibilityAPI
119
@AppStorage(\.promptToCodeGenerateDescription)
1210
var promptToCodeGenerateDescription
1311
@AppStorage(\.promptToCodeGenerateDescriptionInUserPreferredLanguage)
@@ -57,12 +55,6 @@ struct PromptToCodeSettingsView: View {
5755

5856
Text("pt")
5957
}.disabled(true)
60-
61-
Divider()
62-
63-
Toggle(isOn: $settings.acceptSuggestionWithAccessibilityAPI) {
64-
Text("Use accessibility API to accept suggestion in widget")
65-
}.disabled(true)
6658
}
6759
}
6860
}

Core/Sources/HostApp/FeatureSettings/SuggestionSettingsView.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ struct SuggestionSettingsView: View {
99
var realtimeSuggestionDebounce
1010
@AppStorage(\.suggestionPresentationMode)
1111
var suggestionPresentationMode
12-
@AppStorage(\.acceptSuggestionWithAccessibilityAPI)
13-
var acceptSuggestionWithAccessibilityAPI
1412
@AppStorage(\.disableSuggestionFeatureGlobally)
1513
var disableSuggestionFeatureGlobally
1614
@AppStorage(\.suggestionFeatureEnabledProjectList)
@@ -125,16 +123,6 @@ struct SuggestionSettingsView: View {
125123
}
126124
Divider()
127125
}
128-
129-
Group {
130-
Toggle(isOn: $settings.acceptSuggestionWithAccessibilityAPI) {
131-
Text("Use accessibility API to accept suggestion in widget")
132-
}
133-
134-
Text("You can turn it on if the accept button is not working for you.")
135-
.font(.caption)
136-
.foregroundStyle(.secondary)
137-
}
138126
}
139127
}
140128
}

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,21 @@ struct PseudoCommandHandler {
136136
}
137137

138138
func acceptSuggestion() async {
139-
if UserDefaults.shared.value(for: \.acceptSuggestionWithAccessibilityAPI) {
139+
do {
140+
try await Environment.triggerAction("Accept Suggestion")
141+
} catch {
140142
guard let xcode = ActiveApplicationMonitor.activeXcode ?? ActiveApplicationMonitor
141143
.latestXcode else { return }
142144
let application = AXUIElementCreateApplication(xcode.processIdentifier)
143145
guard let focusElement = application.focusedElement,
144146
focusElement.description == "Source Editor"
145147
else { return }
146-
guard let (content, lines, _, cursorPosition) = await getFileContent(sourceEditor: nil)
148+
guard let (
149+
content,
150+
lines,
151+
_,
152+
cursorPosition
153+
) = await getFileContent(sourceEditor: nil)
147154
else {
148155
PresentInWindowSuggestionPresenter()
149156
.presentErrorMessage("Unable to get file content.")
@@ -199,21 +206,15 @@ struct PseudoCommandHandler {
199206
}
200207
}
201208

202-
if let oldScrollPosition, let scrollBar = focusElement.parent?.verticalScrollBar {
209+
if let oldScrollPosition,
210+
let scrollBar = focusElement.parent?.verticalScrollBar
211+
{
203212
AXUIElementSetAttributeValue(
204213
scrollBar,
205214
kAXValueAttribute as CFString,
206215
oldScrollPosition as CFTypeRef
207216
)
208217
}
209-
210-
} catch {
211-
PresentInWindowSuggestionPresenter().presentError(error)
212-
}
213-
} else {
214-
do {
215-
try await Environment.triggerAction("Accept Suggestion")
216-
return
217218
} catch {
218219
PresentInWindowSuggestionPresenter().presentError(error)
219220
}

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ struct WidgetView: View {
161161
struct WidgetContextMenu: View {
162162
@AppStorage(\.useGlobalChat) var useGlobalChat
163163
@AppStorage(\.realtimeSuggestionToggle) var realtimeSuggestionToggle
164-
@AppStorage(\.acceptSuggestionWithAccessibilityAPI) var acceptSuggestionWithAccessibilityAPI
165164
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpacesInSuggestion
166165
@AppStorage(\.disableSuggestionFeatureGlobally) var disableSuggestionFeatureGlobally
167166
@AppStorage(\.suggestionFeatureEnabledProjectList) var suggestionFeatureEnabledProjectList
@@ -227,15 +226,6 @@ struct WidgetContextMenu: View {
227226
}
228227
}
229228

230-
Button(action: {
231-
acceptSuggestionWithAccessibilityAPI.toggle()
232-
}, label: {
233-
Text("Accept Suggestion with Accessibility API")
234-
if acceptSuggestionWithAccessibilityAPI {
235-
Image(systemName: "checkmark")
236-
}
237-
})
238-
239229
Button(action: {
240230
hideCommonPrecedingSpacesInSuggestion.toggle()
241231
}, label: {

Tool/Sources/Preferences/Keys.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ public extension UserDefaultPreferenceKeys {
206206
.init(defaultValue: true, key: "HideCommonPrecedingSpacesInSuggestion")
207207
}
208208

209-
var acceptSuggestionWithAccessibilityAPI: PreferenceKey<Bool> {
210-
.init(defaultValue: false, key: "AcceptSuggestionWithAccessibilityAPI")
211-
}
212-
213209
var suggestionPresentationMode: PreferenceKey<PresentationMode> {
214210
.init(defaultValue: .floatingWidget, key: "SuggestionPresentationMode")
215211
}

0 commit comments

Comments
 (0)