From d2fe0bd4d48ddc1c66b8aa12e588ee480f459099 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 12 Apr 2019 11:13:19 -0500 Subject: [PATCH] Changed timeline behavior to scroll selected entry to middle when next selected entry isn't visible. Issue #604 --- .../Keyboard/TimelineKeyboardShortcuts.plist | 12 +++++ .../Timeline/TimelineViewController.swift | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/NetNewsWire/MainWindow/Timeline/Keyboard/TimelineKeyboardShortcuts.plist b/NetNewsWire/MainWindow/Timeline/Keyboard/TimelineKeyboardShortcuts.plist index bfdc71110..82eb517e8 100644 --- a/NetNewsWire/MainWindow/Timeline/Keyboard/TimelineKeyboardShortcuts.plist +++ b/NetNewsWire/MainWindow/Timeline/Keyboard/TimelineKeyboardShortcuts.plist @@ -2,6 +2,18 @@ + + key + [uparrow] + action + selectNextUp: + + + key + [downarrow] + action + selectNextDown: + key [leftarrow] diff --git a/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift b/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift index 5c0f3719b..db701e6b0 100644 --- a/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift +++ b/NetNewsWire/MainWindow/Timeline/TimelineViewController.swift @@ -253,6 +253,51 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner { NSPasteboard.general.copyObjects(selectedArticles) } + @IBAction func selectNextUp(_ sender: Any?) { + + guard let lastSelectedRow = tableView.selectedRowIndexes.last else { + return + } + + let nextRowIndex = lastSelectedRow - 1 + if nextRowIndex <= 0 { + tableView.scrollTo(row: 0, extraHeight: 0) + } + + tableView.rs_selectRow(nextRowIndex) + + let followingRowIndex = nextRowIndex - 1 + if followingRowIndex < 0 { + return + } + + tableView.scrollToIfNotVisable(index: followingRowIndex) + + } + + @IBAction func selectNextDown(_ sender: Any?) { + + guard let firstSelectedRow = tableView.selectedRowIndexes.first else { + return + } + + let tableMaxIndex = tableView.numberOfRows - 1 + let nextRowIndex = firstSelectedRow + 1 + if nextRowIndex >= tableMaxIndex { + tableView.scrollTo(row: tableMaxIndex, extraHeight: 0) + } + + tableView.rs_selectRow(nextRowIndex) + + let followingRowIndex = nextRowIndex + 1 + if followingRowIndex > tableMaxIndex { + return + } + + tableView.scrollToIfNotVisable(index: followingRowIndex) + + } + func toggleReadStatusForSelectedArticles() { // If any one of the selected articles is unread, then mark them as read.