diff --git a/Multiplatform/Shared/Timeline/TimelineModel.swift b/Multiplatform/Shared/Timeline/TimelineModel.swift index 73d0497c8..fb9edf275 100644 --- a/Multiplatform/Shared/Timeline/TimelineModel.swift +++ b/Multiplatform/Shared/Timeline/TimelineModel.swift @@ -173,14 +173,17 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { } func canMarkAboveAsRead(_ article: Article) -> Bool { + let article = correctedAboveArticle(article) return articles.articlesAbove(article: article).canMarkAllAsRead() } func canMarkBelowAsRead(_ article: Article) -> Bool { + let article = correctedBelowArticle(article) return articles.articlesBelow(article: article).canMarkAllAsRead() } func markAboveAsRead(_ article: Article) { + let article = correctedAboveArticle(article) let articlesToMark = articles.articlesAbove(article: article) guard !articlesToMark.isEmpty else { return } 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) { + let article = correctedBelowArticle(article) let articlesToMark = articles.articlesBelow(article: article) guard !articlesToMark.isEmpty else { return } 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 { + 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 @objc func statusesDidChange(_ note: Notification) {