Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BlockInserterViewModel: ObservableObject {

init(sections: [BlockInserterSection]) {
self.allSections = sections
self.sections = sections
self.sections = sections.filter { $0.category != "gbk-search-only" }

setupSearchObserver()
}
Expand All @@ -36,18 +36,31 @@ class BlockInserterViewModel: ObservableObject {
.store(in: &cancellables)
}

/// Sections visible when browsing (excludes search-only sections).
private var browsableSections: [BlockInserterSection] {
allSections.filter { $0.category != "gbk-search-only" }
}

private func updateFilteredSections(searchText: String) {
if searchText.isEmpty {
sections = allSections
sections = browsableSections
} else {
sections = allSections.compactMap { section in
let filtered = SearchEngine<BlockType>()
.search(query: searchText, in: section.blocks)
return filtered.isEmpty ? nil : BlockInserterSection(
category: section.category,
name: section.name,
blocks: filtered
)
// Flatten all blocks (including search-only) into a single
// ranked list so search results aren't split across sections.
// Deduplicate by ID first since the same block can appear in
// multiple sections (e.g. most-used and its category section).
var seenIDs = Set<String>()
let allBlocks = allSections.flatMap { $0.blocks }.filter { seenIDs.insert($0.id).inserted }
let results = SearchEngine<BlockType>()
.search(query: searchText, in: allBlocks)
if results.isEmpty {
sections = []
} else {
sections = [BlockInserterSection(
category: "gbk-search-results",
name: nil,
blocks: results
)]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct BlockType: Decodable, Identifiable {
var icon: String?
var frecency: Double = 0.0
var isDisabled = false
var isSearchOnly = false
var parents: [String] = []
}

Expand Down
Loading
Loading