diff options
Diffstat (limited to 'src/client/views/global/globalScripts.ts')
-rw-r--r-- | src/client/views/global/globalScripts.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/client/views/global/globalScripts.ts b/src/client/views/global/globalScripts.ts index 0afb3635f..7f6c726d6 100644 --- a/src/client/views/global/globalScripts.ts +++ b/src/client/views/global/globalScripts.ts @@ -271,24 +271,24 @@ ScriptingGlobals.add(function showFreeform(attr: 'hcenter' | 'vcenter' | 'grid' }); /** - * Applies a filter to the selected document (or, if the settings button is pressed, opens the filter panel) + * Applies (or removes) a filter to the selected document for the specified tag + * NOTE: this also opens the filter panel if the settings button is clicked (probably should be a different function) */ // eslint-disable-next-line prefer-arrow-callback -ScriptingGlobals.add(function handleTags(value: string, checkResult?: boolean) { +ScriptingGlobals.add(function setTagFilter(tag: string, added: boolean, checkResult?: boolean) { const selected = DocumentView.SelectedDocs().lastElement(); - const isOptions = value === '-opts-'; - - const isAttrFiltered = (attr: string) => - StrListCast(selected._childFilters) - .map(filter => filter.split(Doc.FilterSep)) - .some(([key, val]) => key === 'tags' && val === attr); + const isOptions = tag === '-opts-'; if (checkResult) { - return isOptions ? false : isAttrFiltered(value); + return isOptions + ? false + : StrListCast(selected._childFilters) // check all filters for one that filters tags:value where value is the tag's name + .map(filter => filter.split(Doc.FilterSep)) + .some(([key, val]) => key === 'tags' && val === tag); } if (!isOptions) { - isAttrFiltered(value) ? Doc.setDocFilter(selected, 'tags', value, 'remove') : Doc.setDocFilter(selected, 'tags', value, 'check'); + added ? Doc.setDocFilter(selected, 'tags', tag, 'check') : Doc.setDocFilter(selected, 'tags', tag, 'remove'); } else { SnappingManager.PropertiesWidth < 5 && SnappingManager.SetPropertiesWidth(0); SnappingManager.SetPropertiesWidth(MainView.Instance.propertiesWidth() < 15 ? 250 : 0); |