From 1f8cc4196a0b11561843bc517ac8eaacc19e7e73 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Tue, 1 Oct 2024 01:02:42 -0400 Subject: [PATCH 1/2] Have duplicates filtering respect search text options. --- Spellbook/SpellFilter.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Spellbook/SpellFilter.swift b/Spellbook/SpellFilter.swift index ae55b41..a26a91b 100644 --- a/Spellbook/SpellFilter.swift +++ b/Spellbook/SpellFilter.swift @@ -155,7 +155,11 @@ 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 - if hideDuplicates { + let isText = (state.searchQuery?.isEmpty) != nil + let applyFiltersToSearch = state.profile?.sortFilterStatus.applyFiltersToSearch ?? false + let searchTextOnly = isText && !applyFiltersToSearch + let doDuplicatesFilter = hideDuplicates && !searchTextOnly + if doDuplicatesFilter { let prefer2024Spells = state.profile?.sortFilterStatus.prefer2024Spells ?? true let rulesetToIgnore = prefer2024Spells ? Ruleset.Rules2014 : Ruleset.Rules2024 let duplicatesFilter = { (spell: Spell) in From 07ca75bc26cb0b58cc9caee628234dc18e1bf167 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Wed, 2 Oct 2024 19:30:18 -0400 Subject: [PATCH 2/2] Have duplicates filtering respect spell list options. Fix bug with text filtering. --- Spellbook/SpellFilter.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Spellbook/SpellFilter.swift b/Spellbook/SpellFilter.swift index a26a91b..cca14a5 100644 --- a/Spellbook/SpellFilter.swift +++ b/Spellbook/SpellFilter.swift @@ -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 } @@ -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 } } @@ -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