Focus the page view's web view when it opens

This commit is contained in:
Ian Gulliver
2026-10-22 20:37:58 -07:00
parent 2e2b898486
commit fa0e521402
+13
View File
@@ -643,6 +643,7 @@ private struct WebPage {
final class Coordinator {
var reloads = 0
var shown = false
}
func makeCoordinator() -> Coordinator {
@@ -659,11 +660,23 @@ private struct WebPage {
private func update(_ view: WKWebView, _ c: Coordinator) {
view.isHidden = !shown
if shown, !c.shown {
focus(view)
}
c.shown = shown
if c.reloads != reloads {
c.reloads = reloads
view.reload()
}
}
private func focus(_ view: WKWebView) {
#if os(macOS)
DispatchQueue.main.async {
unsafe view.window?.makeFirstResponder(view)
}
#endif
}
}
#if os(macOS)