Skip to content

Commit 9402028

Browse files
committed
Disable text field when responding
1 parent 0baa394 commit 9402028

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public struct PromptToCode: ReducerProtocol {
150150
state.code = ""
151151
state.description = ""
152152
state.error = nil
153-
state.prompt = ""
154153

155154
return .run { send in
156155
do {
@@ -207,6 +206,7 @@ public struct PromptToCode: ReducerProtocol {
207206
return .none
208207

209208
case .modifyCodeFinished:
209+
state.prompt = ""
210210
state.isResponding = false
211211
if state.code.isEmpty, state.description.isEmpty {
212212
// if both code and description are empty, we treat it as failed

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,6 @@ extension PromptToCodePanel {
275275
.scaleEffect(x: 1, y: -1, anchor: .center)
276276
}
277277
}
278-
279-
WithViewStore(store, observe: { $0.commandName }) { viewStore in
280-
if let name = viewStore.state {
281-
Text(name)
282-
.font(.footnote)
283-
.foregroundColor(.secondary)
284-
.padding(.top, 12)
285-
.scaleEffect(x: 1, y: -1, anchor: .center)
286-
}
287-
}
288278
}
289279
}
290280
.scaleEffect(x: 1, y: -1, anchor: .center)
@@ -300,8 +290,9 @@ extension PromptToCodePanel {
300290
var canRevert: Bool
301291
}
302292

303-
struct Prompt: Equatable {
293+
struct InputFieldState: Equatable {
304294
@BindingViewState var prompt: String
295+
var isResponding: Bool
305296
}
306297

307298
var body: some View {
@@ -366,7 +357,10 @@ extension PromptToCodePanel {
366357
}
367358

368359
var inputField: some View {
369-
WithViewStore(store, observe: { Prompt(prompt: $0.$prompt) }) { viewStore in
360+
WithViewStore(
361+
store,
362+
observe: { InputFieldState(prompt: $0.$prompt, isResponding: $0.isResponding) }
363+
) { viewStore in
370364
ZStack(alignment: .center) {
371365
// a hack to support dynamic height of TextEditor
372366
Text(viewStore.state.prompt.isEmpty ? "Hi" : viewStore.state.prompt)
@@ -380,10 +374,13 @@ extension PromptToCodePanel {
380374
CustomTextEditor(
381375
text: viewStore.$prompt,
382376
font: .systemFont(ofSize: 14),
377+
isEditable: !viewStore.state.isResponding,
383378
onSubmit: { viewStore.send(.modifyCodeButtonTapped) }
384379
)
385380
.padding(.top, 1)
386381
.padding(.bottom, -1)
382+
.opacity(viewStore.state.isResponding ? 0.5 : 1)
383+
.disabled(viewStore.state.isResponding)
387384
}
388385
}
389386
.focused($isInputAreaFocused)

Tool/Sources/SharedUIComponents/CustomTextEditor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ public struct CustomTextEditor: NSViewRepresentable {
77

88
@Binding public var text: String
99
public let font: NSFont
10+
public let isEditable: Bool
1011
public let onSubmit: () -> Void
1112
public var completions: (_ text: String, _ words: [String], _ range: NSRange) -> [String]
1213

1314
public init(
1415
text: Binding<String>,
1516
font: NSFont,
17+
isEditable: Bool = true,
1618
onSubmit: @escaping () -> Void,
1719
completions: @escaping (_ text: String, _ words: [String], _ range: NSRange)
1820
-> [String] = { _, _, _ in [] }
1921
) {
2022
_text = text
2123
self.font = font
24+
self.isEditable = isEditable
2225
self.onSubmit = onSubmit
2326
self.completions = completions
2427
}
@@ -41,6 +44,7 @@ public struct CustomTextEditor: NSViewRepresentable {
4144
public func updateNSView(_ nsView: NSScrollView, context: Context) {
4245
context.coordinator.completions = completions
4346
let textView = (context.coordinator.theTextView.documentView as! NSTextView)
47+
textView.isEditable = isEditable
4448
guard textView.string != text else { return }
4549
textView.string = text
4650
textView.undoManager?.removeAllActions()

0 commit comments

Comments
 (0)