Skip to content

Commit 6b4e6f8

Browse files
committed
Fix that the suggestion panel counld dance around when the completion panel updates
1 parent c517f66 commit 6b4e6f8

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Core/Sources/SuggestionWidget/WidgetWindowsController.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -373,6 +367,22 @@ private extension WidgetWindowsController {
373367
}
374368
}
375369
}
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+
}
376386
}
377387

378388
extension WidgetWindowsController {

0 commit comments

Comments
 (0)