Skip to content

Commit d0ac2aa

Browse files
committed
Remove PromptToCodeAcceptHandlerDependencyKey
1 parent e534a45 commit d0ac2aa

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,7 @@ public final class GraphicalUserInterfaceController {
298298
dependencies.suggestionWidgetUserDefaultsObservers = .init()
299299
dependencies.chatTabPool = chatTabPool
300300
dependencies.chatTabBuilderCollection = ChatTabFactory.chatTabBuilderCollection
301-
dependencies.promptToCodeAcceptHandler = { promptToCode in
302-
Task {
303-
let handler = PseudoCommandHandler()
304-
await handler.acceptPromptToCode()
305-
if !promptToCode.isContinuous {
306-
NSWorkspace.activatePreviousActiveXcode()
307-
} else {
308-
NSWorkspace.activateThisApp()
309-
}
310-
}
311-
}
312-
301+
313302
#if canImport(ChatTabPersistent) && canImport(ProChatTabs)
314303
dependencies.restoreChatTabInPool = {
315304
await chatTabPool.restore($0)

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ import Foundation
66
import PromptToCodeService
77
import SuggestionBasic
88

9-
public struct PromptToCodeAcceptHandlerDependencyKey: DependencyKey {
10-
public static let liveValue: (PromptToCode.State) -> Void = { _ in
11-
assertionFailure("Please provide a handler")
12-
}
13-
14-
public static let previewValue: (PromptToCode.State) -> Void = { _ in
15-
print("Accept Prompt to Code")
16-
}
17-
}
18-
19-
public extension DependencyValues {
20-
var promptToCodeAcceptHandler: (PromptToCode.State) -> Void {
21-
get { self[PromptToCodeAcceptHandlerDependencyKey.self] }
22-
set { self[PromptToCodeAcceptHandlerDependencyKey.self] = newValue }
23-
}
24-
}
25-
269
@Reducer
2710
public struct PromptToCode {
2811
@ObservableState
@@ -140,9 +123,11 @@ public struct PromptToCode {
140123
case appendNewLineToPromptButtonTapped
141124
}
142125

126+
@Dependency(\.commandHandler) var commandHandler
143127
@Dependency(\.promptToCodeService) var promptToCodeService
144-
@Dependency(\.promptToCodeAcceptHandler) var promptToCodeAcceptHandler
145-
128+
@Dependency(\.activateThisApp) var activateThisApp
129+
@Dependency(\.activatePreviousActiveXcode) var activatePreviousActiveXcode
130+
146131
enum CancellationKey: Hashable {
147132
case modifyCode(State.ID)
148133
}
@@ -258,8 +243,15 @@ public struct PromptToCode {
258243
return .none
259244

260245
case .acceptButtonTapped:
261-
promptToCodeAcceptHandler(state)
262-
return .none
246+
let isContinuous = state.isContinuous
247+
return .run { _ in
248+
await commandHandler.acceptPromptToCode()
249+
if !isContinuous {
250+
activatePreviousActiveXcode()
251+
} else {
252+
activateThisApp()
253+
}
254+
}
263255

264256
case .copyCodeButtonTapped:
265257
NSPasteboard.general.clearContents()

0 commit comments

Comments
 (0)