@@ -373,14 +373,25 @@ extension SuggestionWidgetController {
373373 sourceEditorMonitorTask = nil
374374 observeEditorChangeIfNeeded ( app)
375375
376- guard let fileURL = try ? await Environment . fetchCurrentFileURL ( ) else {
377- // if it's switching to a ui component that is not a text area.
378- if ActiveApplicationMonitor . activeApplication? . isXcode ?? false {
379- suggestionPanelViewModel. content = nil
380- suggestionPanelViewModel. chat = nil
376+ guard let fileURL = await {
377+ // if it's not editor, use the window id as url.
378+ if let activeNonEditorWindow = {
379+ let application = AXUIElementCreateApplication ( app. processIdentifier)
380+ let focusedElement = application. focusedElement
381+ if focusedElement? . description != " Source Editor " {
382+ return application. focusedWindow
383+ }
384+ return nil
385+ } ( ) {
386+ let id = activeNonEditorWindow. identifier. hashValue
387+ return URL ( fileURLWithPath: " /xcode-focused-element/ \( id) " )
381388 }
389+
390+ return try ? await Environment . fetchCurrentFileURL ( )
391+ } ( ) else {
382392 continue
383393 }
394+
384395 guard fileURL != currentFileURL else { continue }
385396 currentFileURL = fileURL
386397 widgetViewModel. currentFileURL = currentFileURL
@@ -478,6 +489,7 @@ extension SuggestionWidgetController {
478489 }
479490 } else if var window = application. focusedWindow,
480491 var frame = application. focusedWindow? . rect,
492+ ![ " menu bar " , " menu bar item " ] . contains ( window. description) ,
481493 frame. size. height > 300 ,
482494 let screen = NSScreen . screens. first ( where: { $0. frame. origin == . zero } ) ,
483495 let firstScreen = NSScreen . main
@@ -591,6 +603,8 @@ extension SuggestionWidgetController {
591603 }
592604
593605 if let provider = await dataSource? . promptToCodeForFile ( at: fileURL) {
606+ if case let . promptToCode( currentProvider) = suggestionPanelViewModel. content,
607+ currentProvider. id == provider. id { return }
594608 suggestionPanelViewModel. content = . promptToCode( provider)
595609 } else if let suggestion = await dataSource? . suggestionForFile ( at: fileURL) {
596610 suggestionPanelViewModel. content = . suggestion( suggestion)
0 commit comments