iOS: Make shift-space scroll up even when the detail view doesn't have focus
This commit is contained in:
parent
5acce87995
commit
82f7f99827
|
@ -293,10 +293,18 @@ class ArticleViewController: UIViewController {
|
|||
return currentWebViewController?.canScrollDown() ?? false
|
||||
}
|
||||
|
||||
func canScrollUp() -> Bool {
|
||||
return currentWebViewController?.canScrollUp() ?? false
|
||||
}
|
||||
|
||||
func scrollPageDown() {
|
||||
currentWebViewController?.scrollPageDown()
|
||||
}
|
||||
|
||||
func scrollPageUp() {
|
||||
currentWebViewController?.scrollPageUp()
|
||||
}
|
||||
|
||||
func stopArticleExtractorIfProcessing() {
|
||||
currentWebViewController?.stopArticleExtractorIfProcessing()
|
||||
}
|
||||
|
|
|
@ -123,17 +123,23 @@ class WebViewController: UIViewController {
|
|||
|
||||
func canScrollDown() -> Bool {
|
||||
guard let webView = webView else { return false }
|
||||
return webView.scrollView.contentOffset.y < finalScrollPosition()
|
||||
return webView.scrollView.contentOffset.y < finalScrollPosition(scrollingUp: false)
|
||||
}
|
||||
|
||||
func scrollPageDown() {
|
||||
func canScrollUp() -> Bool {
|
||||
guard let webView = webView else { return false }
|
||||
return webView.scrollView.contentOffset.y > finalScrollPosition(scrollingUp: true)
|
||||
}
|
||||
|
||||
private func scrollPage(up scrollingUp: Bool) {
|
||||
guard let webView = webView else { return }
|
||||
|
||||
let overlap = 2 * UIFont.systemFont(ofSize: UIFont.systemFontSize).lineHeight * UIScreen.main.scale
|
||||
let scrollToY: CGFloat = {
|
||||
let fullScroll = webView.scrollView.contentOffset.y + webView.scrollView.layoutMarginsGuide.layoutFrame.height - overlap
|
||||
let final = finalScrollPosition()
|
||||
return fullScroll < final ? fullScroll : final
|
||||
let scrollDistance = webView.scrollView.layoutMarginsGuide.layoutFrame.height - overlap;
|
||||
let fullScroll = webView.scrollView.contentOffset.y + (scrollingUp ? -scrollDistance : scrollDistance)
|
||||
let final = finalScrollPosition(scrollingUp: scrollingUp)
|
||||
return (scrollingUp ? fullScroll > final : fullScroll < final) ? fullScroll : final
|
||||
}()
|
||||
|
||||
let convertedPoint = self.view.convert(CGPoint(x: 0, y: 0), to: webView.scrollView)
|
||||
|
@ -141,6 +147,14 @@ class WebViewController: UIViewController {
|
|||
webView.scrollView.setContentOffset(scrollToPoint, animated: true)
|
||||
}
|
||||
|
||||
func scrollPageDown() {
|
||||
scrollPage(up: false)
|
||||
}
|
||||
|
||||
func scrollPageUp() {
|
||||
scrollPage(up: true)
|
||||
}
|
||||
|
||||
func hideClickedImage() {
|
||||
webView?.evaluateJavaScript("hideClickedImage();")
|
||||
}
|
||||
|
@ -539,9 +553,14 @@ private extension WebViewController {
|
|||
|
||||
}
|
||||
|
||||
func finalScrollPosition() -> CGFloat {
|
||||
func finalScrollPosition(scrollingUp: Bool) -> CGFloat {
|
||||
guard let webView = webView else { return 0 }
|
||||
return webView.scrollView.contentSize.height - webView.scrollView.bounds.height + webView.scrollView.safeAreaInsets.bottom
|
||||
|
||||
if scrollingUp {
|
||||
return -webView.scrollView.safeAreaInsets.top
|
||||
} else {
|
||||
return webView.scrollView.contentSize.height - webView.scrollView.bounds.height + webView.scrollView.safeAreaInsets.bottom
|
||||
}
|
||||
}
|
||||
|
||||
func startArticleExtractor() {
|
||||
|
|
|
@ -36,6 +36,10 @@ class RootSplitViewController: UISplitViewController {
|
|||
coordinator.scrollOrGoToNextUnread()
|
||||
}
|
||||
|
||||
@objc func scrollUp(_ sender: Any?) {
|
||||
coordinator.scrollUp()
|
||||
}
|
||||
|
||||
@objc func goToPreviousUnread(_ sender: Any?) {
|
||||
coordinator.selectPrevUnread()
|
||||
}
|
||||
|
|
|
@ -991,6 +991,12 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||
}
|
||||
}
|
||||
|
||||
func scrollUp() {
|
||||
if articleViewController?.canScrollUp() ?? false {
|
||||
articleViewController?.scrollPageUp()
|
||||
}
|
||||
}
|
||||
|
||||
func markAllAsRead(_ articles: [Article]) {
|
||||
markArticlesWithUndo(articles, statusKey: .read, flag: true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue