Mac: Make shift-space scroll up even when the detail view doesn't have focus

Issue #969.
This commit is contained in:
Nate Weaver 2020-07-10 13:33:25 -05:00
parent 4ba2ab4baa
commit 5acce87995
4 changed files with 41 additions and 0 deletions

View File

@ -66,9 +66,17 @@ final class DetailViewController: NSViewController, WKUIDelegate {
currentWebViewController.canScrollDown(callback) currentWebViewController.canScrollDown(callback)
} }
func canScrollUp(_ callback: @escaping (Bool) -> Void) {
currentWebViewController.canScrollUp(callback)
}
override func scrollPageDown(_ sender: Any?) { override func scrollPageDown(_ sender: Any?) {
currentWebViewController.scrollPageDown(sender) currentWebViewController.scrollPageDown(sender)
} }
override func scrollPageUp(_ sender: Any?) {
currentWebViewController.scrollPageUp(sender)
}
// MARK: - Navigation // MARK: - Navigation

View File

@ -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?) { override func scrollPageDown(_ sender: Any?) {
webView.scrollPageDown(sender) webView.scrollPageDown(sender)
} }
override func scrollPageUp(_ sender: Any?) {
webView.scrollPageUp(sender)
}
} }
// MARK: - WKScriptMessageHandler // MARK: - WKScriptMessageHandler

View File

@ -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?) { @IBAction func openArticleInBrowser(_ sender: Any?) {
if let link = currentLink { if let link = currentLink {
Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false) Browser.open(link, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false)

View File

@ -10,6 +10,16 @@
<key>action</key> <key>action</key>
<string>scrollOrGoToNextUnread:</string> <string>scrollOrGoToNextUnread:</string>
</dict> </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> <dict>
<key>title</key> <key>title</key>
<string>Go to Previous Unread</string> <string>Go to Previous Unread</string>