diff --git a/Swiftgram/SGItemListUI/Sources/SGItemListUI.swift b/Swiftgram/SGItemListUI/Sources/SGItemListUI.swift index e1a0db58bb..78d802eac2 100644 --- a/Swiftgram/SGItemListUI/Sources/SGItemListUI.swift +++ b/Swiftgram/SGItemListUI/Sources/SGItemListUI.swift @@ -234,7 +234,8 @@ public func filterSGItemListUIEntrires = [] + var sectionIdsForEntireIncludion: Set = [] + var sectionIdsWithMatches: Set = [] var filteredEntries: [SGItemListUIEntry] = [] func entryMatches(_ entry: SGItemListUIEntry, query: String) -> Bool { @@ -251,12 +252,12 @@ public func filterSGItemListUIEntrires 0 { + let previousEntry = entries[index - 1] + if case .notice = previousEntry {} else { + if !filteredEntries.contains(previousEntry) { + filteredEntries.append(previousEntry) + } + } + } + if !filteredEntries.contains(entry) { + filteredEntries.append(entry) + } + } else { + if !filteredEntries.contains(entry) { + filteredEntries.append(entry) + } + // add next entry if it's notice + // possibly targeting description (notice) for the currently search-matched toggle/setting + if index < entries.count - 1 { + let nextEntry = entries[index + 1] + if case .notice = nextEntry { + if !filteredEntries.contains(nextEntry) { + filteredEntries.append(nextEntry) + } + } + } + } + } else if sectionIdsForEntireIncludion.contains(entry.section) { + if !filteredEntries.contains(entry) { + filteredEntries.append(entry) + } } } }