@@ -97,7 +97,7 @@ public final class SuggestionWidgetController {
9797 private var colorScheme : ColorScheme = . light
9898
9999 public var dataSource : SuggestionWidgetDataSource ?
100-
100+
101101 public nonisolated init( ) {
102102 #warning(
103103 " TODO: A test is initializing this class for unknown reasons, try a better way to avoid this. "
@@ -117,6 +117,7 @@ public final class SuggestionWidgetController {
117117 windowChangeObservationTask = nil
118118 self . observeXcodeWindowChangeIfNeeded ( app)
119119 }
120+ await self . updateContentForActiveEditor ( )
120121 self . updateWindowLocation ( )
121122 } else {
122123 if ActiveApplicationMonitor . activeApplication? . bundleIdentifier != Bundle
@@ -248,7 +249,7 @@ public extension SuggestionWidgetController {
248249 Task {
249250 if let chat = await dataSource?.chatForFile(at: fileURL) {
250251 suggestionPanelViewModel.chat = chat
251-
252+
252253 Task { @MainActor in
253254 // looks like we need a delay.
254255 try await Task.sleep(nanoseconds: 150_000_000)
@@ -276,6 +277,7 @@ extension SuggestionWidgetController {
276277 let notifications = AXNotificationStream(
277278 app: app,
278279 notificationNames:
280+ kAXApplicationActivatedNotification,
279281 kAXMovedNotification,
280282 kAXResizedNotification,
281283 kAXMainWindowChangedNotification,
@@ -287,12 +289,11 @@ extension SuggestionWidgetController {
287289 for await notification in notifications {
288290 guard let self else { return }
289291 try Task.checkCancellation()
290- self.updateWindowLocation(animated: false)
291- panelWindow.orderFront(nil)
292- widgetWindow.orderFront(nil)
293- tabWindow.orderFront(nil)
294292
295- if notification.name == kAXFocusedUIElementChangedNotification {
293+ if [
294+ kAXFocusedUIElementChangedNotification,
295+ kAXApplicationActivatedNotification,
296+ ].contains(notification.name) {
296297 sourceEditorMonitorTask?.cancel()
297298 sourceEditorMonitorTask = nil
298299 observeEditorChangeIfNeeded(app)
@@ -309,6 +310,8 @@ extension SuggestionWidgetController {
309310 currentFileURL = fileURL
310311 await updateContentForActiveEditor(fileURL: fileURL)
311312 }
313+
314+ self.updateWindowLocation(animated: false)
312315 }
313316 }
314317 }
@@ -428,17 +431,17 @@ extension SuggestionWidgetController {
428431 return
429432 }
430433
431- if let suggestion = await dataSource? . suggestionForFile ( at: fileURL) {
432- suggestionPanelViewModel. content = . suggestion( suggestion)
433- } else {
434- suggestionPanelViewModel. content = nil
435- }
436-
437434 if let chat = await dataSource? . chatForFile ( at: fileURL) {
438435 suggestionPanelViewModel. chat = chat
439436 } else {
440437 suggestionPanelViewModel. chat = nil
441438 }
439+
440+ if let suggestion = await dataSource? . suggestionForFile ( at: fileURL) {
441+ suggestionPanelViewModel. content = . suggestion( suggestion)
442+ } else {
443+ suggestionPanelViewModel. content = nil
444+ }
442445 }
443446}
444447
0 commit comments