Skip to content

Commit d171043

Browse files
committed
Prevent opening multiple prompt to code panel
1 parent edc8c29 commit d171043

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ extension WindowBaseCommandHandler {
410410
let viewStore = Service.shared.guiController.viewStore
411411

412412
_ = await Task { @MainActor in
413-
viewStore.send(.promptToCodeGroup(.createPromptToCode(.init(
413+
// if there is already a prompt to code presenting, we should not present another one
414+
viewStore.send(.promptToCodeGroup(.activateOrCreatePromptToCode(.init(
414415
code: code,
415416
selectionRange: selection,
416417
language: codeLanguage,

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodeGroup.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public struct PromptToCodeGroup: ReducerProtocol {
6767
}
6868

6969
public enum Action: Equatable {
70+
/// Activate the prompt to code if it exists or create it if it doesn't
71+
case activateOrCreatePromptToCode(PromptToCodeInitialState)
7072
case createPromptToCode(PromptToCodeInitialState)
7173
case updatePromptToCodeRange(id: PromptToCode.State.ID, range: CursorRange)
7274
case discardAcceptedPromptToCodeIfNotContinuous(id: PromptToCode.State.ID)
@@ -80,6 +82,13 @@ public struct PromptToCodeGroup: ReducerProtocol {
8082
public var body: some ReducerProtocol<State, Action> {
8183
Reduce { state, action in
8284
switch action {
85+
case let .activateOrCreatePromptToCode(s):
86+
guard state.activePromptToCode == nil else {
87+
return .none
88+
}
89+
return .run { send in
90+
await send(.createPromptToCode(s))
91+
}
8392
case let .createPromptToCode(s):
8493
let newPromptToCode = PromptToCode.State(
8594
code: s.code,

0 commit comments

Comments
 (0)