diff options
author | bobzel <zzzman@gmail.com> | 2021-03-12 11:48:54 -0500 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-03-12 11:48:54 -0500 |
commit | 75194d8218e1747d177ec018e3cf025b8d8906bc (patch) | |
tree | 2f7faf642a9977620f9a83b3e8feddec3fad8d48 /src/fields/Doc.ts | |
parent | 2f5051296883d3473e2eb1df648d27a0102d04ed (diff) |
changed setDocFilter to not take undefined as a modfied & added toggle param. added single click on marquee annotator to create an annotation. extended PDF sidebar to have filter buttons.
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r-- | src/fields/Doc.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 041d9ce7f..d590695d0 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -1066,26 +1066,27 @@ export namespace Doc { // filters document in a container collection: // all documents with the specified value for the specified key are included/excluded // based on the modifiers :"check", "x", undefined - export function setDocFilter(target: Opt<Doc>, key: string, value: any, modifiers?: "remove" | "match" | "check" | "x" | undefined) { + export function setDocFilter(target: Opt<Doc>, key: string, value: any, modifiers: "remove" | "match" | "check" | "x", toggle?: boolean) { const container = target ?? CollectionDockingView.Instance.props.Document; const docFilters = Cast(container._docFilters, listSpec("string"), []); runInAction(() => { for (let i = 0; i < docFilters.length; i++) { const fields = docFilters[i].split(":"); // split key:value:modifier if (fields[0] === key && (fields[1] === value || modifiers === "match" || modifiers === "remove")) { - if (fields[2] === modifiers && modifiers && fields[1] === value) return; + if (fields[2] === modifiers && modifiers && fields[1] === value) { + if (toggle) modifiers = "remove"; + else return; + } docFilters.splice(i, 1); container._docFilters = new List<string>(docFilters); break; } } - if (typeof modifiers === "string") { - if (!docFilters.length && modifiers === "match" && value === undefined) { - container._docFilters = undefined; - } else if (modifiers !== "remove") { - docFilters.push(key + ":" + value + ":" + modifiers); - container._docFilters = new List<string>(docFilters); - } + if (!docFilters.length && modifiers === "match" && value === undefined) { + container._docFilters = undefined; + } else if (modifiers !== "remove") { + docFilters.push(key + ":" + value + ":" + modifiers); + container._docFilters = new List<string>(docFilters); } }); } @@ -1336,5 +1337,5 @@ Scripting.addGlobal(function selectedDocs(container: Doc, excludeCollections: bo (!excludeCollections || d.type !== DocumentType.COL || !Cast(d.data, listSpec(Doc), null))); return docs.length ? new List(docs) : prevValue; }); -Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: "match" | "check" | "x" | undefined) { Doc.setDocFilter(container, key, value, modifiers); }); +Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers: "match" | "check" | "x" | "remove") { Doc.setDocFilter(container, key, value, modifiers); }); Scripting.addGlobal(function setDocFilterRange(container: Doc, key: string, range: number[]) { Doc.setDocFilterRange(container, key, range); }); |