Skip to content

Commit 4c5ca42

Browse files
committed
Fixed that focused editor not loaded at first
1 parent 09e679b commit 4c5ca42

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Core/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,29 @@ public final class XcodeInspector: ObservableObject {
108108
latestActiveXcode = xcode
109109
activeDocumentURL = xcode.documentURL
110110
focusedWindow = xcode.focusedWindow
111+
112+
let setFocusedElement = { [weak self] in
113+
guard let self else { return }
114+
focusedElement = xcode.appElement.focusedElement
115+
if let editorElement = focusedElement, editorElement.isSourceEditor {
116+
focusedEditor = .init(
117+
runningApplication: xcode.runningApplication,
118+
element: editorElement
119+
)
120+
} else {
121+
focusedEditor = nil
122+
}
123+
}
111124

125+
setFocusedElement()
112126
let focusedElementChanged = Task { @MainActor in
113127
let notification = AXNotificationStream(
114128
app: xcode.runningApplication,
115129
notificationNames: kAXFocusedUIElementChangedNotification
116130
)
117131
for await _ in notification {
118132
try Task.checkCancellation()
119-
focusedElement = xcode.appElement.focusedElement
120-
if let editorElement = focusedElement, editorElement.isSourceEditor {
121-
focusedEditor = .init(
122-
runningApplication: xcode.runningApplication,
123-
element: editorElement
124-
)
125-
} else {
126-
focusedEditor = nil
127-
}
133+
setFocusedElement()
128134
}
129135
}
130136

0 commit comments

Comments
 (0)