@@ -219,6 +219,7 @@ public final class SuggestionWidgetController {
219219 }
220220
221221 Task { @MainActor in
222+ var switchTask : Task < Void , Error > ?
222223 suggestionPanelViewModel. onActiveTabChanged = { activeTab in
223224 #warning("""
224225 TODO: There should be a better way for that
@@ -228,12 +229,15 @@ public final class SuggestionWidgetController {
228229 switch activeTab {
229230 case .suggestion:
230231 guard NSApp.activationPolicy() != .prohibited else { return }
231- Task {
232+ switchTask?.cancel()
233+ switchTask = Task {
232234 try await Environment.makeXcodeActive()
235+ try Task.checkCancellation()
233236 NSApp.setActivationPolicy(.prohibited)
234237 }
235238 case .chat:
236239 guard NSApp.activationPolicy() != .accessory else { return }
240+ switchTask?.cancel()
237241 NSApp.setActivationPolicy(.accessory)
238242 }
239243 }
@@ -376,12 +380,14 @@ extension SuggestionWidgetController {
376380 scroll
377381 ) {
378382 guard let self else { return }
383+ guard ActiveApplicationMonitor.activeXcode != nil else { return }
379384 try Task.checkCancellation()
380385 self.updateWindowLocation(animated: false)
381386 }
382387 } else {
383388 for await _ in merge(selectionRangeChange, scroll) {
384389 guard let self else { return }
390+ guard ActiveApplicationMonitor.activeXcode != nil else { return }
385391 try Task.checkCancellation()
386392 let mode = UserDefaults.shared.value(for: \. suggestionWidgetPositionMode)
387393 if mode != . alignToTextCursor { break }
0 commit comments