From 0c9786f1a202a26041af50849b96af29996b2f68 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 3 Mar 2024 23:01:00 -0800 Subject: [PATCH] Rename FeedNode to SidebarItemNode. --- iOS/SceneCoordinator.swift | 84 +++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index d2d77a1a9..818b5e325 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -37,7 +37,7 @@ enum ShowFeedName { case feed } -struct FeedNode: Hashable { +struct SidebarItemNode: Hashable { var node: Node var sidebarItemID: SidebarItemIdentifier @@ -82,8 +82,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { private var readFilterEnabledTable = [SidebarItemIdentifier: Bool]() /// Flattened tree structure for the Sidebar - private var shadowTable = [(sectionID: String, feedNodes: [FeedNode])]() - + private var shadowTable = [(sectionID: String, sidebarItemNodes: [SidebarItemNode])]() + private(set) var preSearchTimelineFeed: SidebarItem? private var lastSearchString = "" private var lastSearchScope: SearchScope? = nil @@ -178,8 +178,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { let prevIndexPath: IndexPath? = { if indexPath.row - 1 < 0 { for i in (0.. 0 { - return IndexPath(row: shadowTable[i].feedNodes.count - 1, section: i) + if shadowTable[i].sidebarItemNodes.count > 0 { + return IndexPath(row: shadowTable[i].sidebarItemNodes.count - 1, section: i) } } return nil @@ -197,9 +197,9 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { } let nextIndexPath: IndexPath? = { - if indexPath.row + 1 >= shadowTable[indexPath.section].feedNodes.count { + if indexPath.row + 1 >= shadowTable[indexPath.section].sidebarItemNodes.count { for i in indexPath.section + 1.. 0 { + if shadowTable[i].sidebarItemNodes.count > 0 { return IndexPath(row: 0, section: i) } } @@ -310,7 +310,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { for sectionNode in treeController.rootNode.childNodes { markExpanded(sectionNode) - shadowTable.append((sectionID: "", feedNodes: [FeedNode]())) + shadowTable.append((sectionID: "", sidebarItemNodes: [SidebarItemNode]())) } NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil) @@ -616,7 +616,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { } func numberOfRows(in section: Int) -> Int { - return shadowTable[section].feedNodes.count + return shadowTable[section].sidebarItemNodes.count } func nodeFor(_ section: Int) -> Node? { @@ -627,10 +627,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { guard indexPath.section > -1 && indexPath.row > -1 && indexPath.section < shadowTable.count && - indexPath.row < shadowTable[indexPath.section].feedNodes.count else { + indexPath.row < shadowTable[indexPath.section].sidebarItemNodes.count else { return nil } - return shadowTable[indexPath.section].feedNodes[indexPath.row].node + return shadowTable[indexPath.section].sidebarItemNodes[indexPath.row].node } func indexPathFor(_ object: AnyObject) -> IndexPath? { @@ -642,10 +642,10 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { func indexPathFor(_ node: Node) -> IndexPath? { - let feedNode = FeedNode(node) + let sidebarItemNode = SidebarItemNode(node) for i in 0.. IndexPath { - guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].feedNodes.count else { - return IndexPath(row: shadowTable[shadowTable.count - 1].feedNodes.count - 1, section: shadowTable.count - 1) + guard indexPath.section < shadowTable.count && indexPath.row < shadowTable[indexPath.section].sidebarItemNodes.count else { + return IndexPath(row: shadowTable[shadowTable.count - 1].sidebarItemNodes.count - 1, section: shadowTable.count - 1) } return indexPath } @@ -1492,9 +1492,9 @@ private extension SceneCoordinator { func addShadowTableToFilterExceptions() { for section in shadowTable { - for feedNode in section.feedNodes { - if let feed = feedNode.node.representedObject as? SidebarItem, let feedID = feed.sidebarItemID { - treeControllerDelegate.addFilterException(feedID) + for sidebarItemNode in section.sidebarItemNodes { + if let sidebarItem = sidebarItemNode.node.representedObject as? SidebarItem, let sidebarItemID = sidebarItem.sidebarItemID { + treeControllerDelegate.addFilterException(sidebarItemID) } } } @@ -1521,28 +1521,28 @@ private extension SceneCoordinator { } func rebuildShadowTable() -> ShadowTableChanges { - var newShadowTable = [(sectionID: String, feedNodes: [FeedNode])]() + var newShadowTable = [(sectionID: String, sidebarItemNodes: [SidebarItemNode])]() for i in 0..() var deletes = Set() - let oldFeedNodes = shadowTable.first(where: { $0.sectionID == newSectionRows.sectionID })?.feedNodes ?? [FeedNode]() - - let diff = newSectionRows.feedNodes.difference(from: oldFeedNodes).inferringMoves() + let oldFeedNodes = shadowTable.first(where: { $0.sectionID == newSectionRows.sectionID })?.sidebarItemNodes ?? [SidebarItemNode]() + + let diff = newSectionRows.sidebarItemNodes.difference(from: oldFeedNodes).inferringMoves() for change in diff { switch change { case .insert(let offset, _, let associated): @@ -1582,7 +1582,7 @@ private extension SceneCoordinator { // We need to reload the difference in expanded rows to get the disclosure arrows correct when programmatically changing their state var reloads = Set() - for (index, newFeedNode) in newSectionRows.feedNodes.enumerated() { + for (index, newFeedNode) in newSectionRows.sidebarItemNodes.enumerated() { if let newFeedNodeContainerID = (newFeedNode.node.representedObject as? Container)?.containerID { if expandedTableDifference.contains(newFeedNodeContainerID) { reloads.insert(index) @@ -1625,10 +1625,10 @@ private extension SceneCoordinator { return ShadowTableChanges(deletes: deletes, inserts: inserts, moves: moves, rowChanges: changes) } - func shadowTableContains(_ feed: SidebarItem) -> Bool { + func shadowTableContains(_ sidebarItem: SidebarItem) -> Bool { for section in shadowTable { - for feedNode in section.feedNodes { - if let nodeFeed = feedNode.node.representedObject as? SidebarItem, nodeFeed.sidebarItemID == feed.sidebarItemID { + for sidebarItemNode in section.sidebarItemNodes { + if let node = sidebarItemNode.node.representedObject as? SidebarItem, node.sidebarItemID == sidebarItem.sidebarItemID { return true } } @@ -1769,9 +1769,9 @@ private extension SceneCoordinator { let nextIndexPath: IndexPath = { if indexPath.row - 1 < 0 { if indexPath.section - 1 < 0 { - return IndexPath(row: shadowTable[shadowTable.count - 1].feedNodes.count - 1, section: shadowTable.count - 1) + return IndexPath(row: shadowTable[shadowTable.count - 1].sidebarItemNodes.count - 1, section: shadowTable.count - 1) } else { - return IndexPath(row: shadowTable[indexPath.section - 1].feedNodes.count - 1, section: indexPath.section - 1) + return IndexPath(row: shadowTable[indexPath.section - 1].sidebarItemNodes.count - 1, section: indexPath.section - 1) } } else { return IndexPath(row: indexPath.row - 1, section: indexPath.section) @@ -1781,7 +1781,7 @@ private extension SceneCoordinator { if selectPrevUnreadFeedFetcher(startingWith: nextIndexPath) { return } - let maxIndexPath = IndexPath(row: shadowTable[shadowTable.count - 1].feedNodes.count - 1, section: shadowTable.count - 1) + let maxIndexPath = IndexPath(row: shadowTable[shadowTable.count - 1].sidebarItemNodes.count - 1, section: shadowTable.count - 1) selectPrevUnreadFeedFetcher(startingWith: maxIndexPath) } @@ -1795,7 +1795,7 @@ private extension SceneCoordinator { if indexPath.section == i { return indexPath.row } else { - return shadowTable[i].feedNodes.count - 1 + return shadowTable[i].sidebarItemNodes.count - 1 } }() @@ -1874,7 +1874,7 @@ private extension SceneCoordinator { // Increment or wrap around the IndexPath let nextIndexPath: IndexPath = { - if indexPath.row + 1 >= shadowTable[indexPath.section].feedNodes.count { + if indexPath.row + 1 >= shadowTable[indexPath.section].sidebarItemNodes.count { if indexPath.section + 1 >= shadowTable.count { return IndexPath(row: 0, section: 0) } else { @@ -1909,7 +1909,7 @@ private extension SceneCoordinator { } }() - for j in startingRow.. Bool { - guard let feedNode = nodeFor(sidebarItemID: sidebarItemID), let feedIndexPath = indexPathFor(feedNode) else { return false } - - selectFeed(indexPath: feedIndexPath) { + guard let sidebarItemNode = nodeFor(sidebarItemID: sidebarItemID), let indexPath = indexPathFor(sidebarItemNode) else { return false } + + selectFeed(indexPath: indexPath) { self.selectArticleInCurrentFeed(articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) }