Merge pull request #2248 from Wevah/shift-space
Make shift-space scroll up in the detail view even when it doesn't have focus
This commit is contained in:
commit
6672013111
|
@ -66,10 +66,18 @@ final class DetailViewController: NSViewController, WKUIDelegate {
|
|||
currentWebViewController.canScrollDown(callback)
|
||||
}
|
||||
|
||||
func canScrollUp(_ callback: @escaping (Bool) -> Void) {
|
||||
currentWebViewController.canScrollUp(callback)
|
||||
}
|
||||
|
||||
override func scrollPageDown(_ sender: Any?) {
|
||||
currentWebViewController.scrollPageDown(sender)
|
||||
}
|
||||
|
||||
override func scrollPageUp(_ sender: Any?) {
|
||||
currentWebViewController.scrollPageUp(sender)
|
||||
}
|
||||
|
||||
// MARK: - Navigation
|
||||
|
||||
func focus() {
|
||||
|
|
|
@ -167,9 +167,19 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
func canScrollUp(_ completion: @escaping (Bool) -> Void) {
|
||||
fetchScrollInfo { (scrollInfo) in
|
||||
completion(scrollInfo?.canScrollUp ?? false)
|
||||
}
|
||||
}
|
||||
|
||||
override func scrollPageDown(_ sender: Any?) {
|
||||
webView.scrollPageDown(sender)
|
||||
}
|
||||
|
||||
override func scrollPageUp(_ sender: Any?) {
|
||||
webView.scrollPageUp(sender)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - WKScriptMessageHandler
|
||||
|
|
|
@ -264,6 +264,19 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
}
|
||||
}
|
||||
|
||||
@IBAction func scrollUp(_ sender: Any?) {
|
||||
guard let detailViewController = detailViewController else {
|
||||
return
|
||||
}
|
||||
detailViewController.canScrollUp { (canScroll) in
|
||||
if (canScroll) {
|
||||
NSCursor.setHiddenUntilMouseMoves(true)
|
||||
detailViewController.scrollPageUp(sender)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@IBAction func openArticleInBrowser(_ sender: Any?) {
|
||||
if let link = currentLink {
|
||||
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)
|
||||
|
|
|
@ -10,6 +10,16 @@
|
|||
<key>action</key>
|
||||
<string>scrollOrGoToNextUnread:</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>title</key>
|
||||
<string>Scroll or Go to Next Unread</string>
|
||||
<key>key</key>
|
||||
<string>[space]</string>
|
||||
<key>shiftModifier</key>
|
||||
<true/>
|
||||
<key>action</key>
|
||||
<string>scrollUp:</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>title</key>
|
||||
<string>Go to Previous Unread</string>
|
||||
|
|
|
@ -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,10 +553,15 @@ private extension WebViewController {
|
|||
|
||||
}
|
||||
|
||||
func finalScrollPosition() -> CGFloat {
|
||||
func finalScrollPosition(scrollingUp: Bool) -> CGFloat {
|
||||
guard let webView = webView else { return 0 }
|
||||
|
||||
if scrollingUp {
|
||||
return -webView.scrollView.safeAreaInsets.top
|
||||
} else {
|
||||
return webView.scrollView.contentSize.height - webView.scrollView.bounds.height + webView.scrollView.safeAreaInsets.bottom
|
||||
}
|
||||
}
|
||||
|
||||
func startArticleExtractor() {
|
||||
if let link = article?.preferredLink, let extractor = ArticleExtractor(link) {
|
||||
|
|
|
@ -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