Maintain scroll position when changing themes

This commit is contained in:
Maurice Parker
2021-09-11 20:53:57 -05:00
parent baad458138
commit abd66ea1bb
2 changed files with 20 additions and 11 deletions

View File

@@ -55,6 +55,7 @@ final class DetailWebViewController: NSViewController {
private let detailIconSchemeHandler = DetailIconSchemeHandler()
private var waitingForFirstReload = false
private var windowScrollY: CGFloat?
private let keyboardDelegate = DetailKeyboardDelegate()
private struct MessageName {
@@ -143,7 +144,10 @@ final class DetailWebViewController: NSViewController {
}
@objc func currentArticleThemeDidChangeNotification(_ note: Notification) {
reloadHTML()
fetchScrollInfo() { scrollInfo in
self.windowScrollY = scrollInfo?.offsetY
self.reloadHTML()
}
}
// MARK: Media Functions
@@ -226,6 +230,11 @@ extension DetailWebViewController: WKNavigationDelegate, WKUIDelegate {
webView.isHidden = false
}
}
if let windowScrollY = windowScrollY {
webView.evaluateJavaScript("window.scrollTo(0, \(windowScrollY));")
self.windowScrollY = nil
}
}
// WKUIDelegate