Skip group rows when going to next unread. Fix #273.

This commit is contained in:
Brent Simmons 2018-02-15 17:50:31 -08:00
parent f8f78810ef
commit d081f041f8
1 changed files with 16 additions and 6 deletions

View File

@ -179,7 +179,7 @@ import RSCore
func canGoToNextUnread() -> Bool { func canGoToNextUnread() -> Bool {
if let _ = rowContainingNextUnread() { if let _ = nextSelectableRowWithUnreadArticle() {
return true return true
} }
return false return false
@ -187,7 +187,7 @@ import RSCore
func goToNextUnread() { func goToNextUnread() {
guard let row = rowContainingNextUnread() else { guard let row = nextSelectableRowWithUnreadArticle() else {
assertionFailure("goToNextUnread called before checking if there is a next unread.") assertionFailure("goToNextUnread called before checking if there is a next unread.")
return return
} }
@ -380,14 +380,24 @@ private extension SidebarViewController {
return false return false
} }
func rowContainingNextUnread() -> Int? { func rowIsGroupItem(_ row: Int) -> Bool {
if let node = nodeForRow(row), outlineView.isGroupItem(node) {
return true
}
return false
}
func nextSelectableRowWithUnreadArticle() -> Int? {
// Skip group items, because they should never be selected.
let selectedRow = outlineView.selectedRow let selectedRow = outlineView.selectedRow
let numberOfRows = outlineView.numberOfRows let numberOfRows = outlineView.numberOfRows
var row = selectedRow + 1 var row = selectedRow + 1
while (row < numberOfRows) { while (row < numberOfRows) {
if rowHasAtLeastOneUnreadArticle(row) { if rowHasAtLeastOneUnreadArticle(row) && !rowIsGroupItem(row) {
return row return row
} }
row += 1 row += 1
@ -395,7 +405,7 @@ private extension SidebarViewController {
row = 0 row = 0
while (row <= selectedRow) { while (row <= selectedRow) {
if rowHasAtLeastOneUnreadArticle(row) { if rowHasAtLeastOneUnreadArticle(row) && !rowIsGroupItem(row) {
return row return row
} }
row += 1 row += 1