diff options
author | bobzel <zzzman@gmail.com> | 2024-09-20 14:49:46 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-09-20 14:49:46 -0400 |
commit | 702949ed50a1d9819d58a6154fee20d086664505 (patch) | |
tree | ea1e8fc9300b8ea96f7c6ee1e63023ba5f7c1620 /src/client/views/global/globalScripts.ts | |
parent | 77e087625bd02cfa170e3f1903b0a744b81380ce (diff) | |
parent | 650ddd4c72510ed29d023d4861dedede0737d3b9 (diff) |
Merge branch 'master' into zach-starter
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); |