Skip to content

Commit aa35079

Browse files
committed
Tweak real-time suggestion indicator
1 parent 054dcc4 commit aa35079

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

Core/Sources/Service/GUI/RealtimeSuggestionIndicatorController.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class RealtimeSuggestionIndicatorController {
1414
@Published var isPrefetching = false
1515
@Published var progress: Double = 1
1616
private var prefetchTask: Task<Void, Error>?
17-
17+
1818
@MainActor
1919
func prefetch() {
2020
prefetchTask?.cancel()
@@ -28,12 +28,11 @@ final class RealtimeSuggestionIndicatorController {
2828
}
2929
}
3030
}
31-
31+
3232
@MainActor
3333
func endPrefetch() {
3434
withAnimation(.easeOut(duration: 0.2)) {
3535
isPrefetching = false
36-
progress = 1
3736
}
3837
}
3938
}
@@ -68,6 +67,10 @@ final class RealtimeSuggestionIndicatorController {
6867
viewModel.progress = 0
6968
}
7069
}
70+
}.onDisappear {
71+
withAnimation(.default) {
72+
viewModel.progress = 1
73+
}
7174
}
7275
}
7376
}
@@ -202,6 +205,9 @@ final class RealtimeSuggestionIndicatorController {
202205
let application = AXUIElementCreateApplication(activeXcode.processIdentifier)
203206
if let focusElement: AXUIElement = try? application
204207
.copyValue(key: kAXFocusedUIElementAttribute),
208+
let focusElementType: String = try? focusElement
209+
.copyValue(key: kAXDescriptionAttribute),
210+
focusElementType == "Source Editor",
205211
let selectedRange: AXValue = try? focusElement
206212
.copyValue(key: kAXSelectedTextRangeAttribute),
207213
let rect: AXValue = try? focusElement.copyParameterizedValue(
@@ -231,7 +237,7 @@ final class RealtimeSuggestionIndicatorController {
231237
func triggerPrefetchAnimation() {
232238
viewModel.prefetch()
233239
}
234-
240+
235241
func endPrefetchAnimation() {
236242
viewModel.endPrefetch()
237243
}

Core/Sources/Service/SuggestionCommandHandler/CommentBaseCommandHandler.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ struct CommentBaseCommandHandler: SuggestionCommandHanlder {
119119
}
120120

121121
func presentRealtimeSuggestions(editor: EditorContent) async throws -> UpdatedContent? {
122+
defer {
123+
Task {
124+
await GraphicalUserInterfaceController.shared.realtimeSuggestionIndicatorController
125+
.endPrefetchAnimation()
126+
}
127+
}
128+
122129
let fileURL = try await Environment.fetchCurrentFileURL()
123130
let (workspace, filespace) = try await Workspace
124131
.fetchOrCreateWorkspaceIfNeeded(fileURL: fileURL)
@@ -134,10 +141,7 @@ struct CommentBaseCommandHandler: SuggestionCommandHanlder {
134141
guard filespace.suggestionSourceSnapshot == snapshot else { return nil }
135142

136143
let presenter = PresentInCommentSuggestionPresenter()
137-
138-
await GraphicalUserInterfaceController.shared.realtimeSuggestionIndicatorController
139-
.endPrefetchAnimation()
140-
144+
141145
return try await presenter.presentSuggestion(
142146
for: filespace,
143147
in: workspace,

0 commit comments

Comments
 (0)