Skip to content

Commit a81e385

Browse files
committed
Allow setting custom debounce
1 parent 74eeee3 commit a81e385

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Core/Sources/Service/AutoTrigger.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,19 @@ public actor AutoTrigger {
8585
}()
8686

8787
let escape = 0x35
88+
89+
guard await Environment.frontmostXcodeWindowIsEditor() else { continue }
8890

8991
guard event.type == .keyUp,
9092
event.getIntegerValueField(.keyboardEventKeycode) != escape
9193
else { continue }
9294

9395
triggerTask = Task { @ServiceActor in
94-
try? await Task.sleep(nanoseconds: 500_000_000)
96+
try? await Task.sleep(nanoseconds: UInt64(
97+
UserDefaults.shared
98+
.value(forKey: SettingsKey.realtimeSuggestionDebounce) as? Int
99+
?? 700_000_000
100+
))
95101
if Task.isCancelled { return }
96102
os_log(.info, "Prefetch suggestions.")
97103
let fileURL = try? await Environment.fetchCurrentFileURL()

Core/Sources/XPCShared/UserDefaults.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public extension UserDefaults {
66

77
public enum SettingsKey {
88
public static let nodePath = "NodePath"
9-
public static let realtimeSuggestionState = "RealtimeSuggestionState"
9+
public static let realtimeSuggestionToggle = "RealtimeSuggestionToggle"
10+
public static let realtimeSuggestionDebounce = "RealtimeSuggestionDebounce"
1011
}

0 commit comments

Comments
 (0)