summaryrefslogtreecommitdiff
path: root/macos/Sources/Helpers/Extensions
diff options
context:
space:
mode:
authorMitchell Hashimoto <m@mitchellh.com>2025-06-10 13:03:30 -0700
committerMitchell Hashimoto <m@mitchellh.com>2025-06-11 15:18:02 -0700
commit4d33a73fc4640b19cb6160942c5bdcd2a8102fb9 (patch)
treef7ac86ebe4d0c678d3c3a4797ae5c5fd2d49c0f1 /macos/Sources/Helpers/Extensions
parentc3d65d3975f91773f10fb19e10911e0f4d6463aa (diff)
wip: redo terminal window styling
Diffstat (limited to 'macos/Sources/Helpers/Extensions')
-rw-r--r--macos/Sources/Helpers/Extensions/NSView+Extension.swift27
1 files changed, 27 insertions, 0 deletions
diff --git a/macos/Sources/Helpers/Extensions/NSView+Extension.swift b/macos/Sources/Helpers/Extensions/NSView+Extension.swift
index 48284df74..121d9a62a 100644
--- a/macos/Sources/Helpers/Extensions/NSView+Extension.swift
+++ b/macos/Sources/Helpers/Extensions/NSView+Extension.swift
@@ -13,6 +13,19 @@ extension NSView {
return false
}
+}
+
+// MARK: View Traversal and Search
+
+extension NSView {
+ /// Returns the absolute root view by walking up the superview chain.
+ var rootView: NSView {
+ var root: NSView = self
+ while let superview = root.superview {
+ root = superview
+ }
+ return root
+ }
/// Recursively finds and returns the first descendant view that has the given class name.
func firstDescendant(withClassName name: String) -> NSView? {
@@ -54,4 +67,18 @@ extension NSView {
return nil
}
+
+ /// Finds and returns the first view with the given class name starting from the absolute root of the view hierarchy.
+ /// This includes private views like title bar views.
+ func firstViewFromRoot(withClassName name: String) -> NSView? {
+ let root = rootView
+
+ // Check if the root view itself matches
+ if String(describing: type(of: root)) == name {
+ return root
+ }
+
+ // Otherwise search descendants
+ return root.firstDescendant(withClassName: name)
+ }
}