Focus the page view's web view when it opens
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user