Skip to content

Commit e703f8f

Browse files
committed
Automatically activate the text field when a chat box is created
1 parent a646e29 commit e703f8f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public final class SuggestionWidgetController {
7979
)
8080
it.setIsVisible(true)
8181
it.canBecomeKeyChecker = { [suggestionPanelViewModel] in
82-
if case .chat = suggestionPanelViewModel.activeTab { return false }
82+
if case .chat = suggestionPanelViewModel.activeTab { return true }
8383
return false
8484
}
8585
return it
@@ -299,6 +299,11 @@ public extension SuggestionWidgetController {
299299
func presentChatRoom(_ chatRoom: ChatRoom, fileURL: URL) {
300300
if fileURL == currentFileURL || currentFileURL == nil {
301301
suggestionPanelViewModel.chat = chatRoom
302+
Task { @MainActor in
303+
// looks like we need a delay.
304+
try await Task.sleep(nanoseconds: 100_000_000)
305+
NSApplication.shared.activate(ignoringOtherApps: true)
306+
}
302307
}
303308
widgetViewModel.isProcessing = false
304309
chatForFiles[fileURL] = chatRoom
@@ -342,8 +347,11 @@ extension SuggestionWidgetController {
342347
observeEditorChangeIfNeeded(app)
343348
344349
guard let fileURL = try? await Environment.fetchCurrentFileURL() else {
345-
suggestionPanelViewModel.content = nil
346-
suggestionPanelViewModel.chat = nil
350+
// if it's switching to a ui component that is not a text area.
351+
if ActiveApplicationMonitor.activeApplication?.isXcode ?? false {
352+
suggestionPanelViewModel.content = nil
353+
suggestionPanelViewModel.chat = nil
354+
}
347355
continue
348356
}
349357
guard fileURL != currentFileURL else { continue }

0 commit comments

Comments
 (0)