Skip to content

Commit e2b4fbb

Browse files
committed
Add func to get window from url
1 parent 6dcde78 commit e2b4fbb

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

Tool/Sources/XcodeInspector/Apps/XcodeAppInstanceInspector.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,22 @@ extension XcodeAppInstanceInspector {
391391
let workspaces = Self.updateWorkspace(workspaces, with: workspaceInfoInVisibleSpace)
392392
self.workspaces = workspaces
393393
}
394+
395+
public func workspaceWindow(
396+
forWorkspaceURL url: URL
397+
) -> AXUIElement? {
398+
let windows = appElement.windows.filter { $0.identifier == "Xcode.WorkspaceWindow" }
399+
400+
for window in windows {
401+
if let workspaceURL = WorkspaceXcodeWindowInspector
402+
.extractWorkspaceURL(windowElement: window),
403+
workspaceURL == url
404+
{
405+
return window
406+
}
407+
}
408+
return nil
409+
}
394410

395411
/// Use the project path as the workspace identifier.
396412
nonisolated static func workspaceIdentifier(_ window: AXUIElement) -> WorkspaceIdentifier {
@@ -482,8 +498,9 @@ private func isCompletionPanel(_ element: AXUIElement) -> Bool {
482498
public extension AXUIElement {
483499
var editorArea: AXUIElement? {
484500
if description == "editor area" { return self }
485-
var area: AXUIElement? = nil
501+
var area: AXUIElement?
486502
traverse { element, level in
503+
print(element.description)
487504
if level > 10 {
488505
return .skipDescendants
489506
}
@@ -492,14 +509,14 @@ public extension AXUIElement {
492509
return .stopSearching
493510
}
494511
if element.description == "navigator" {
495-
return .skipDescendantsAndSiblings
512+
return .skipDescendants
496513
}
497-
514+
498515
return .continueSearching(())
499516
}
500517
return area
501518
}
502-
519+
503520
var tabBars: [AXUIElement] {
504521
guard let editorArea else { return [] }
505522

0 commit comments

Comments
 (0)