11import ActiveApplicationMonitor
22import AppKit
33import AsyncAlgorithms
4+ import AXExtension
45import AXNotificationStream
56import CGEventObserver
67import Environment
@@ -166,7 +167,7 @@ public class RealtimeSuggestionController {
166167 #warning(
167168 " TODO: Any method to avoid using AppleScript to check that completion panel is presented? "
168169 )
169- if await Environment . frontmostXcodeWindowIsEditor ( ) {
170+ if isCommentMode , await Environment . frontmostXcodeWindowIsEditor ( ) {
170171 if Task . isCancelled { return }
171172 self . triggerPrefetchDebounced ( force: true )
172173 }
@@ -190,8 +191,8 @@ public class RealtimeSuggestionController {
190191 if Task . isCancelled { return }
191192
192193 os_log ( . info, " Prefetch suggestions. " )
193-
194- if !force, await !Environment. frontmostXcodeWindowIsEditor ( ) {
194+
195+ if !force, isCommentMode , await !Environment. frontmostXcodeWindowIsEditor ( ) {
195196 os_log ( . info, " Completion panel is open, blocked. " )
196197 return
197198 }
@@ -235,87 +236,3 @@ public class RealtimeSuggestionController {
235236 return application. focusedWindow? . child ( identifier: " _XC_COMPLETION_TABLE_ " ) != nil
236237 }
237238}
238-
239- extension AXUIElement {
240- var identifier : String {
241- ( try ? copyValue ( key: kAXIdentifierAttribute) ) ?? " "
242- }
243-
244- var value : String {
245- ( try ? copyValue ( key: kAXValueAttribute) ) ?? " "
246- }
247-
248- var focusedElement : AXUIElement ? {
249- try ? copyValue ( key: kAXFocusedUIElementAttribute)
250- }
251-
252- var description : String {
253- ( try ? copyValue ( key: kAXDescriptionAttribute) ) ?? " "
254- }
255-
256- var selectedTextRange : Range < Int > ? {
257- guard let value: AXValue = try ? copyValue ( key: kAXSelectedTextRangeAttribute)
258- else { return nil }
259- var range : CFRange = . init( location: 0 , length: 0 )
260- if AXValueGetValue ( value, . cfRange, & range) {
261- return Range ( . init( location: range. location, length: range. length) )
262- }
263- return nil
264- }
265-
266- var sharedFocusElements : [ AXUIElement ] {
267- ( try ? copyValue ( key: kAXChildrenAttribute) ) ?? [ ]
268- }
269-
270- var window : AXUIElement ? {
271- try ? copyValue ( key: kAXWindowAttribute)
272- }
273-
274- var focusedWindow : AXUIElement ? {
275- try ? copyValue ( key: kAXFocusedWindowAttribute)
276- }
277-
278- var topLevelElement : AXUIElement ? {
279- try ? copyValue ( key: kAXTopLevelUIElementAttribute)
280- }
281-
282- var rows : [ AXUIElement ] {
283- ( try ? copyValue ( key: kAXRowsAttribute) ) ?? [ ]
284- }
285-
286- var parent : AXUIElement ? {
287- try ? copyValue ( key: kAXParentAttribute)
288- }
289-
290- var children : [ AXUIElement ] {
291- ( try ? copyValue ( key: kAXChildrenAttribute) ) ?? [ ]
292- }
293-
294- var visibleChildren : [ AXUIElement ] {
295- ( try ? copyValue ( key: kAXVisibleChildrenAttribute) ) ?? [ ]
296- }
297-
298- var isFocused : Bool {
299- ( try ? copyValue ( key: kAXFocusedAttribute) ) ?? false
300- }
301-
302- var isEnabled : Bool {
303- ( try ? copyValue ( key: kAXEnabledAttribute) ) ?? false
304- }
305-
306- func child( identifier: String ) -> AXUIElement ? {
307- for child in children {
308- if child. identifier == identifier { return child }
309- if let target = child. child ( identifier: identifier) { return target }
310- }
311- return nil
312- }
313-
314- func visibleChild( identifier: String ) -> AXUIElement ? {
315- for child in visibleChildren {
316- if child. identifier == identifier { return child }
317- if let target = child. visibleChild ( identifier: identifier) { return target }
318- }
319- return nil
320- }
321- }
0 commit comments