Support a new secret user default JalkutRespectFolderExpansionOnNextUnread, and revise the "next unread" strategy so that whether the search for a next unread wraps around to the top or not is parameterized.

This commit is contained in:
Daniel Jalkut
2020-11-01 17:33:48 -05:00
parent 2229811df0
commit 1ced4448ea
4 changed files with 67 additions and 45 deletions

View File

@@ -20,18 +20,21 @@ extension Array where Element == Article {
return self[row]
}
func rowOfNextUnreadArticle(_ selectedRow: Int) -> Int? {
func orderedRowIndexes(fromIndex startIndex: Int, wrappingToTop wrapping: Bool) -> [Int] {
if startIndex >= self.count {
// Wrap around to the top if specified
return wrapping ? Array<Int>(0..<self.count) : []
} else {
// Start at the selection and wrap around to the beginning
return Array<Int>(startIndex..<self.count) + (wrapping ? Array<Int>(0..<startIndex) : [])
}
}
func rowOfNextUnreadArticle(_ selectedRow: Int, wrappingToTop wrapping: Bool) -> Int? {
if isEmpty {
return nil
}
var rowIndex = selectedRow
while(true) {
rowIndex = rowIndex + 1
if rowIndex >= count {
break
}
for rowIndex in orderedRowIndexes(fromIndex: selectedRow + 1, wrappingToTop: wrapping) {
let article = articleAtRow(rowIndex)!
if !article.status.read {
return rowIndex