Correct about/below mark as read to take into account multiple select

This commit is contained in:
Maurice Parker 2020-07-17 18:15:42 -05:00
parent 11bd3dce22
commit 538d886bf4
1 changed files with 20 additions and 0 deletions

View File

@ -173,14 +173,17 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
} }
func canMarkAboveAsRead(_ article: Article) -> Bool { func canMarkAboveAsRead(_ article: Article) -> Bool {
let article = correctedAboveArticle(article)
return articles.articlesAbove(article: article).canMarkAllAsRead() return articles.articlesAbove(article: article).canMarkAllAsRead()
} }
func canMarkBelowAsRead(_ article: Article) -> Bool { func canMarkBelowAsRead(_ article: Article) -> Bool {
let article = correctedBelowArticle(article)
return articles.articlesBelow(article: article).canMarkAllAsRead() return articles.articlesBelow(article: article).canMarkAllAsRead()
} }
func markAboveAsRead(_ article: Article) { func markAboveAsRead(_ article: Article) {
let article = correctedAboveArticle(article)
let articlesToMark = articles.articlesAbove(article: article) let articlesToMark = articles.articlesAbove(article: article)
guard !articlesToMark.isEmpty else { return } guard !articlesToMark.isEmpty else { return }
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articlesToMark, markingRead: true, undoManager: undoManager) else { guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articlesToMark, markingRead: true, undoManager: undoManager) else {
@ -190,6 +193,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
} }
func markBelowAsRead(_ article: Article) { func markBelowAsRead(_ article: Article) {
let article = correctedBelowArticle(article)
let articlesToMark = articles.articlesBelow(article: article) let articlesToMark = articles.articlesBelow(article: article)
guard !articlesToMark.isEmpty else { return } guard !articlesToMark.isEmpty else { return }
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articlesToMark, markingRead: true, undoManager: undoManager) else { guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: articlesToMark, markingRead: true, undoManager: undoManager) else {
@ -226,6 +230,22 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
private extension TimelineModel { private extension TimelineModel {
func correctedAboveArticle(_ article: Article) -> Article {
if selectedArticles.contains(article) {
return selectedArticles.first!
} else {
return article
}
}
func correctedBelowArticle(_ article: Article) -> Article {
if selectedArticles.contains(article) {
return selectedArticles.last!
} else {
return article
}
}
// MARK: Notifications // MARK: Notifications
@objc func statusesDidChange(_ note: Notification) { @objc func statusesDidChange(_ note: Notification) {