Skip to content

Commit d1d73a9

Browse files
committed
Update to let escape to cancel in-flight real-time suggestion fetches
1 parent f6e8fdb commit d1d73a9

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Core/Sources/Service/AutoTrigger.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public actor AutoTrigger {
6464
if task == nil {
6565
task = Task { [stream = eventObserver.stream] in
6666
var triggerTask: Task<Void, Error>?
67-
for await eventType in stream {
67+
for await event in stream {
6868
triggerTask?.cancel()
6969
if Task.isCancelled { break }
7070
guard await Environment.isXcodeActive() else { continue }
@@ -77,7 +77,11 @@ public actor AutoTrigger {
7777
}
7878
}
7979

80-
guard eventType == .keyUp else { continue }
80+
let escape = 0x35
81+
82+
guard event.type == .keyUp,
83+
event.getIntegerValueField(.keyboardEventKeycode) != escape
84+
else { continue }
8185

8286
triggerTask = Task { @ServiceActor in
8387
try? await Task.sleep(nanoseconds: 1_500_000_000)

Core/Sources/Service/CGEventObserver.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ public protocol CGEventObserverType {
66
@discardableResult
77
func activateIfPossible() -> Bool
88
func deactivate()
9-
var stream: AsyncStream<CGEventType> { get }
9+
var stream: AsyncStream<CGEvent> { get }
1010
var isEnabled: Bool { get }
1111
}
1212

1313
final class CGEventObserver: CGEventObserverType {
14-
let stream: AsyncStream<CGEventType>
14+
let stream: AsyncStream<CGEvent>
1515
var isEnabled: Bool { port != nil }
1616

17-
private var continuation: AsyncStream<CGEventType>.Continuation
17+
private var continuation: AsyncStream<CGEvent>.Continuation
1818
private var port: CFMachPort?
1919
private let eventsOfInterest: Set<CGEventType> = [
2020
.keyUp,
@@ -33,7 +33,7 @@ final class CGEventObserver: CGEventObserverType {
3333
}
3434

3535
init() {
36-
var continuation: AsyncStream<CGEventType>.Continuation!
36+
var continuation: AsyncStream<CGEvent>.Continuation!
3737
stream = AsyncStream { c in
3838
continuation = c
3939
}
@@ -71,9 +71,9 @@ final class CGEventObserver: CGEventObserverType {
7171
}
7272

7373
if let continuation = continuationPointer?
74-
.assumingMemoryBound(to: AsyncStream<CGEventType>.Continuation.self)
74+
.assumingMemoryBound(to: AsyncStream<CGEvent>.Continuation.self)
7575
{
76-
continuation.pointee.yield(eventType)
76+
continuation.pointee.yield(event)
7777
}
7878

7979
return .passRetained(event)

0 commit comments

Comments
 (0)