@@ -28,6 +28,8 @@ actor WidgetWindowsController: NSObject {
2828 var updateWindowLocationTask : Task < Void , Error > ?
2929 var lastUpdateWindowLocationTime = Date ( timeIntervalSince1970: 0 )
3030
31+ var beatingCompletionPanelTask : Task < Void , Error > ?
32+
3133 deinit {
3234 userDefaultsObservers. presentationModeChangeObserver. onChange = { }
3335 observeToAppTask? . cancel ( )
@@ -61,15 +63,7 @@ actor WidgetWindowsController: NSObject {
6163
6264 xcodeInspector. $completionPanel. sink { [ weak self] newValue in
6365 Task { [ weak self] in
64- if newValue == nil {
65- // so that the buttons on the suggestion panel could be
66- // clicked
67- // before the completion panel updates the location of the
68- // suggestion panel
69- try await Task . sleep ( nanoseconds: 400_000_000 )
70- }
71- await self ? . updateWindowLocation ( animated: false , immediately: false )
72- await self ? . updateWindowOpacity ( immediately: false )
66+ await self ? . handleCompletionPanelChange ( isDisplaying: newValue != nil )
7367 }
7468 } . store ( in: & cancellable)
7569
@@ -299,10 +293,10 @@ private extension WidgetWindowsController {
299293 await send ( . updateFocusingDocumentURL)
300294 }
301295
302- func updateWidgetsAndNotifyChangeOfEditor( ) async {
303- await updateWindowLocation ( animated: false , immediately: false )
304- await updateWindowOpacity ( immediately: false )
296+ func updateWidgetsAndNotifyChangeOfEditor( immediately: Bool ) async {
305297 await send ( . panel( . switchToAnotherEditorAndUpdateContent) )
298+ await updateWindowLocation ( animated: false , immediately: immediately)
299+ await updateWindowOpacity ( immediately: immediately)
306300 }
307301
308302 func updateWidgets( ) async {
@@ -313,9 +307,11 @@ private extension WidgetWindowsController {
313307 switch notification. kind {
314308 case . focusedWindowChanged, . focusedUIElementChanged:
315309 await hideWidgetForTransitions ( )
316- await updateWidgetsAndNotifyChangeOfEditor ( )
317- case . applicationActivated, . mainWindowChanged:
318- await updateWidgetsAndNotifyChangeOfEditor ( )
310+ await updateWidgetsAndNotifyChangeOfEditor ( immediately: true )
311+ case . applicationActivated:
312+ await updateWidgetsAndNotifyChangeOfEditor ( immediately: false )
313+ case . mainWindowChanged:
314+ await updateWidgetsAndNotifyChangeOfEditor ( immediately: false )
319315 case . applicationDeactivated,
320316 . moved,
321317 . resized,
@@ -371,6 +367,22 @@ private extension WidgetWindowsController {
371367 }
372368 }
373369 }
370+
371+ func handleCompletionPanelChange( isDisplaying: Bool ) {
372+ beatingCompletionPanelTask? . cancel ( )
373+ beatingCompletionPanelTask = Task {
374+ if !isDisplaying {
375+ // so that the buttons on the suggestion panel could be
376+ // clicked
377+ // before the completion panel updates the location of the
378+ // suggestion panel
379+ try await Task . sleep ( nanoseconds: 400_000_000 )
380+ }
381+
382+ await updateWindowLocation ( animated: false , immediately: false )
383+ await updateWindowOpacity ( immediately: false )
384+ }
385+ }
374386}
375387
376388extension WidgetWindowsController {
0 commit comments