Skip to content

Commit

Permalink
Have duplicates filtering respect spell list options. Fix bug with te…
Browse files Browse the repository at this point in the history
…xt filtering.
  • Loading branch information
Carifio24 committed Oct 2, 2024
1 parent 1f8cc41 commit 07ca75b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Spellbook/SpellFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func filterSpell(spell: Spell, sortFilterStatus: SortFilterStatus, spellFilterSt
toHide = toHide || !sortFilterStatus.getSomaticFilter(spell.somatic)
toHide = toHide || !sortFilterStatus.getMaterialFilter(spell.material)
toHide = toHide || !sortFilterStatus.getRoyaltyFilter(spell.royalty)
toHide = toHide || (isText && !spellName.contains(text))
toHide = toHide || (isText && !spellName.contains(searchText))
return !toHide
}

Expand All @@ -120,7 +120,7 @@ func createFilter(state: SpellbookAppState) -> (Spell) -> Bool {
// First, we filter the data
let searchText = state.searchQuery ?? ""
let isText = !searchText.isEmpty

guard let cp = state.profile else {
return { spell in return false }
}
Expand Down Expand Up @@ -155,10 +155,13 @@ func filteredSpellList(state: SpellbookAppState) -> [Spell] {
// I'd rather avoid a second pass, but since linked spells won't necessarily
// have the same data, we can't generally know whether we need to filter a spell
// as a duplicate on the first pass
let isText = (state.searchQuery?.isEmpty) != nil
let isText = !(state.searchQuery?.isEmpty ?? true)
let applyFiltersToSearch = state.profile?.sortFilterStatus.applyFiltersToSearch ?? false
let searchTextOnly = isText && !applyFiltersToSearch
let doDuplicatesFilter = hideDuplicates && !searchTextOnly
let applyFiltersToLists = state.profile?.sortFilterStatus.applyFiltersToLists ?? false
let statusSet = state.profile?.sortFilterStatus.isStatusSet() ?? false
let listsAndSearchOnly = !applyFiltersToLists && statusSet
let doDuplicatesFilter = hideDuplicates && !searchTextOnly && !listsAndSearchOnly
if doDuplicatesFilter {
let prefer2024Spells = state.profile?.sortFilterStatus.prefer2024Spells ?? true
let rulesetToIgnore = prefer2024Spells ? Ruleset.Rules2014 : Ruleset.Rules2024
Expand Down

0 comments on commit 07ca75b

Please sign in to comment.