Change next/prev feed searches so that they skip collapsed sections. Issue#1755

This commit is contained in:
Maurice Parker 2020-01-30 18:37:22 -07:00
parent 63e15d78c2
commit df3c78b1c6
1 changed files with 16 additions and 29 deletions

View File

@ -161,37 +161,19 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
private(set) var showFeedNames = false private(set) var showFeedNames = false
private(set) var showIcons = false private(set) var showIcons = false
var isPrevFeedAvailable: Bool {
guard let indexPath = currentFeedIndexPath else {
return false
}
return indexPath.section > 0 || indexPath.row > 0
}
var isNextFeedAvailable: Bool {
guard let indexPath = currentFeedIndexPath else {
return false
}
let nextIndexPath: IndexPath = {
if indexPath.row + 1 >= shadowTable[indexPath.section].count {
return IndexPath(row: 0, section: indexPath.section + 1)
} else {
return IndexPath(row: indexPath.row + 1, section: indexPath.section)
}
}()
return nextIndexPath.section < shadowTable.count && nextIndexPath.row < shadowTable[nextIndexPath.section].count
}
var prevFeedIndexPath: IndexPath? { var prevFeedIndexPath: IndexPath? {
guard isPrevFeedAvailable, let indexPath = currentFeedIndexPath else { guard let indexPath = currentFeedIndexPath else {
return nil return nil
} }
let prevIndexPath: IndexPath = { let prevIndexPath: IndexPath? = {
if indexPath.row - 1 < 0 { if indexPath.row - 1 < 0 {
return IndexPath(row: shadowTable[indexPath.section - 1].count - 1, section: indexPath.section - 1) for i in (0..<indexPath.section).reversed() {
if shadowTable[i].count > 0 {
return IndexPath(row: shadowTable[i].count - 1, section: i)
}
}
return nil
} else { } else {
return IndexPath(row: indexPath.row - 1, section: indexPath.section) return IndexPath(row: indexPath.row - 1, section: indexPath.section)
} }
@ -201,13 +183,18 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
} }
var nextFeedIndexPath: IndexPath? { var nextFeedIndexPath: IndexPath? {
guard isNextFeedAvailable, let indexPath = currentFeedIndexPath else { guard let indexPath = currentFeedIndexPath else {
return nil return nil
} }
let nextIndexPath: IndexPath = { let nextIndexPath: IndexPath? = {
if indexPath.row + 1 >= shadowTable[indexPath.section].count { if indexPath.row + 1 >= shadowTable[indexPath.section].count {
return IndexPath(row: 0, section: indexPath.section + 1) for i in indexPath.section + 1..<shadowTable.count {
if shadowTable[i].count > 0 {
return IndexPath(row: 0, section: i)
}
}
return nil
} else { } else {
return IndexPath(row: indexPath.row + 1, section: indexPath.section) return IndexPath(row: indexPath.row + 1, section: indexPath.section)
} }