Skip to content

Commit d80d931

Browse files
committed
Move KeybindingManager to Core
1 parent 1629510 commit d80d931

File tree

8 files changed

+545
-26
lines changed

8 files changed

+545
-26
lines changed

Core/Package.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ let package = Package(
101101
// quick hack to support custom UserDefaults
102102
// https://github.com/sindresorhus/KeyboardShortcuts
103103
.package(url: "https://github.com/intitni/KeyboardShortcuts", branch: "main"),
104+
.package(url: "https://github.com/intitni/CGEventOverride", from: "1.2.1"),
104105
].pro,
105106
targets: [
106107
// MARK: - Main
@@ -127,6 +128,7 @@ let package = Package(
127128
"ServiceUpdateMigration",
128129
"ChatGPTChatTab",
129130
"PlusFeatureFlag",
131+
"KeyBindingManager",
130132
.product(name: "XPCShared", package: "Tool"),
131133
.product(name: "SuggestionProvider", package: "Tool"),
132134
.product(name: "Workspace", package: "Tool"),
@@ -377,6 +379,24 @@ let package = Package(
377379
],
378380
path: "Sources/ChatContextCollectors/SystemInfoChatContextCollector"
379381
),
382+
383+
// MARK: Key Binding
384+
385+
.target(
386+
name: "KeyBindingManager",
387+
dependencies: [
388+
.product(name: "Workspace", package: "Tool"),
389+
.product(name: "Preferences", package: "Tool"),
390+
.product(name: "Logger", package: "Tool"),
391+
.product(name: "CGEventOverride", package: "CGEventOverride"),
392+
.product(name: "AppMonitoring", package: "Tool"),
393+
.product(name: "UserDefaultsObserver", package: "Tool"),
394+
]
395+
),
396+
.testTarget(
397+
name: "KeyBindingManagerTests",
398+
dependencies: ["KeyBindingManager"]
399+
),
380400
]
381401
)
382402

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,24 @@ struct SuggestionSettingsGeneralSectionView: View {
172172
Text("Real-time suggestion")
173173
}
174174

175-
#if canImport(ProHostApp)
176-
WithFeatureEnabled(\.tabToAcceptSuggestion) {
177-
Toggle(isOn: $settings.acceptSuggestionWithTab) {
178-
HStack {
179-
Text("Accept suggestion with Tab")
175+
Toggle(isOn: $settings.acceptSuggestionWithTab) {
176+
HStack {
177+
Text("Accept suggestion with Tab")
180178

181-
Button(action: {
182-
isTabToAcceptSuggestionModifierViewOpen = true
183-
}) {
184-
Image(systemName: "gearshape.fill")
185-
}
186-
.buttonStyle(.plain)
179+
Button(action: {
180+
isTabToAcceptSuggestionModifierViewOpen = true
181+
}) {
182+
Image(systemName: "gearshape.fill")
187183
}
188-
}.sheet(isPresented: $isTabToAcceptSuggestionModifierViewOpen) {
189-
TabToAcceptSuggestionModifierView()
184+
.buttonStyle(.plain)
190185
}
186+
}.sheet(isPresented: $isTabToAcceptSuggestionModifierViewOpen) {
187+
TabToAcceptSuggestionModifierView()
191188
}
192189

193190
Toggle(isOn: $settings.dismissSuggestionWithEsc) {
194191
Text("Dismiss suggestion with ESC")
195192
}
196-
#endif
197193

198194
HStack {
199195
Toggle(isOn: $settings.disableSuggestionFeatureGlobally) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
import Workspace
3+
4+
public final class KeyBindingManager {
5+
let tabToAcceptSuggestion: TabToAcceptSuggestion
6+
7+
public init(
8+
workspacePool: WorkspacePool,
9+
acceptSuggestion: @escaping () -> Void,
10+
dismissSuggestion: @escaping () -> Void
11+
) {
12+
tabToAcceptSuggestion = .init(
13+
workspacePool: workspacePool,
14+
acceptSuggestion: acceptSuggestion,
15+
dismissSuggestion: dismissSuggestion
16+
)
17+
}
18+
19+
public func start() {
20+
tabToAcceptSuggestion.start()
21+
}
22+
23+
@MainActor
24+
public func stopForExit() {
25+
tabToAcceptSuggestion.stopForExit()
26+
}
27+
}
28+
29+

0 commit comments

Comments
 (0)