Add scroll or go to next unread keyboard shortcut

This commit is contained in:
Maurice Parker 2019-09-05 21:14:19 -05:00
parent 18d442d901
commit a2dda5f0f8
4 changed files with 36 additions and 1 deletions

View File

@ -184,7 +184,32 @@ class DetailViewController: UIViewController {
webView.becomeFirstResponder()
}
func finalScrollPosition() -> CGFloat {
return webView.scrollView.contentSize.height - webView.scrollView.bounds.size.height + webView.scrollView.contentInset.bottom
}
func canScrollDown() -> Bool {
return webView.scrollView.contentOffset.y < finalScrollPosition()
}
func scrollPageDown() {
let scrollToY: CGFloat = {
let fullScroll = webView.scrollView.contentOffset.y + webView.scrollView.bounds.size.height
let final = finalScrollPosition()
if fullScroll < final {
return fullScroll
} else {
return final
}
}()
let convertedPoint = self.view.convert(CGPoint(x: 0, y: 0), to: webView.scrollView)
let scrollToPoint = CGPoint(x: convertedPoint.x, y: scrollToY)
webView.scrollView.setContentOffset(scrollToPoint, animated: true)
}
}
//print("\(candidateY) : \(webView.scrollView.contentSize.height)")
class ArticleActivityItemSource: NSObject, UIActivityItemSource {

View File

@ -60,7 +60,7 @@ private extension KeyboardManager {
switch(key) {
case "[space]":
return " "
return "\u{0020}"
case "[uparrow]":
return UIKeyCommand.inputUpArrow
case "[downarrow]":

View File

@ -19,7 +19,9 @@ class RootSplitViewController: UISplitViewController {
}
// MARK: Keyboard Shortcuts
@objc func scrollOrGoToNextUnread(_ sender: Any?) {
coordinator.scrollOrGoToNextUnread()
}
@objc func goToPreviousUnread(_ sender: Any?) {

View File

@ -753,6 +753,14 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
func scrollOrGoToNextUnread() {
if detailViewController?.canScrollDown() ?? false {
detailViewController?.scrollPageDown()
} else {
selectNextUnread()
}
}
func markAllAsRead(_ articles: [Article]) {
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articles, markingRead: true, undoManager: undoManager) else {
return