Skip to content

Commit 6bdbf0b

Browse files
committed
Support applying modifiers to tab to accept suggestion
1 parent 863459c commit 6bdbf0b

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

Core/Sources/HostApp/FeatureSettings/Suggestion/SuggestionSettingsGeneralSectionView.swift

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct SuggestionSettingsGeneralSectionView: View {
9797
@StateObject var settings = Settings()
9898
@State var isSuggestionFeatureEnabledListPickerOpen = false
9999
@State var isSuggestionFeatureDisabledLanguageListViewOpen = false
100+
@State var isTabToAcceptSuggestionModifierViewOpen = false
100101

101102
var body: some View {
102103
Form {
@@ -174,7 +175,18 @@ struct SuggestionSettingsGeneralSectionView: View {
174175
#if canImport(ProHostApp)
175176
WithFeatureEnabled(\.tabToAcceptSuggestion) {
176177
Toggle(isOn: $settings.acceptSuggestionWithTab) {
177-
Text("Accept suggestion with Tab")
178+
HStack {
179+
Text("Accept suggestion with Tab")
180+
181+
Button(action: {
182+
isTabToAcceptSuggestionModifierViewOpen = true
183+
}) {
184+
Image(systemName: "gearshape.fill")
185+
}
186+
.buttonStyle(.plain)
187+
}
188+
}.sheet(isPresented: $isTabToAcceptSuggestionModifierViewOpen) {
189+
TabToAcceptSuggestionModifierView()
178190
}
179191
}
180192

@@ -248,10 +260,70 @@ struct SuggestionSettingsGeneralSectionView: View {
248260
}
249261
}
250262
}
263+
264+
struct TabToAcceptSuggestionModifierView: View {
265+
final class Settings: ObservableObject {
266+
@AppStorage(\.acceptSuggestionWithModifierCommand)
267+
var needCommand
268+
@AppStorage(\.acceptSuggestionWithModifierOption)
269+
var needOption
270+
@AppStorage(\.acceptSuggestionWithModifierShift)
271+
var needShift
272+
@AppStorage(\.acceptSuggestionWithModifierControl)
273+
var needControl
274+
@AppStorage(\.acceptSuggestionWithModifierOnlyForSwift)
275+
var onlyForSwift
276+
}
277+
278+
@StateObject var settings = Settings()
279+
@Environment(\.dismiss) var dismiss
280+
281+
var body: some View {
282+
VStack(spacing: 0) {
283+
Form {
284+
Text("Accept suggestion with modifier")
285+
.font(.headline)
286+
HStack {
287+
Toggle(isOn: $settings.needCommand) {
288+
Text("Command")
289+
}
290+
Toggle(isOn: $settings.needOption) {
291+
Text("Option")
292+
}
293+
Toggle(isOn: $settings.needShift) {
294+
Text("Shift")
295+
}
296+
Toggle(isOn: $settings.needControl) {
297+
Text("Control")
298+
}
299+
}
300+
Toggle(isOn: $settings.onlyForSwift) {
301+
Text("Only require modifiers for Swift")
302+
}
303+
}
304+
.padding()
305+
306+
Divider()
307+
308+
HStack {
309+
Spacer()
310+
Button(action: { dismiss() }) {
311+
Text("Done")
312+
}
313+
.keyboardShortcut(.defaultAction)
314+
}
315+
.padding()
316+
}
317+
}
318+
}
251319
}
252320

253321
#Preview {
254322
SuggestionSettingsGeneralSectionView()
255323
.padding()
256324
}
257325

326+
#Preview {
327+
SuggestionSettingsGeneralSectionView.TabToAcceptSuggestionModifierView()
328+
}
329+

Pro

Submodule Pro updated from 9790545 to b049af9

Tool/Sources/Preferences/Keys.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,26 @@ public extension UserDefaultPreferenceKeys {
363363
var acceptSuggestionWithTab: PreferenceKey<Bool> {
364364
.init(defaultValue: true, key: "AcceptSuggestionWithTab")
365365
}
366+
367+
var acceptSuggestionWithModifierCommand: PreferenceKey<Bool> {
368+
.init(defaultValue: false, key: "SuggestionWithModifierCommand")
369+
}
370+
371+
var acceptSuggestionWithModifierOption: PreferenceKey<Bool> {
372+
.init(defaultValue: false, key: "SuggestionWithModifierOption")
373+
}
374+
375+
var acceptSuggestionWithModifierControl: PreferenceKey<Bool> {
376+
.init(defaultValue: false, key: "SuggestionWithModifierControl")
377+
}
378+
379+
var acceptSuggestionWithModifierShift: PreferenceKey<Bool> {
380+
.init(defaultValue: false, key: "SuggestionWithModifierShift")
381+
}
382+
383+
var acceptSuggestionWithModifierOnlyForSwift: PreferenceKey<Bool> {
384+
.init(defaultValue: false, key: "SuggestionWithModifierOnlyForSwift")
385+
}
366386

367387
var dismissSuggestionWithEsc: PreferenceKey<Bool> {
368388
.init(defaultValue: true, key: "DismissSuggestionWithEsc")

0 commit comments

Comments
 (0)