aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 9147fc33f..2f9dc7f51 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -903,9 +903,6 @@ export namespace Doc {
export function UserDoc(): Doc { return manager._user_doc; }
export function SharingDoc(): Doc { return Cast(Doc.UserDoc().mySharedDocs, Doc, null); }
export function LinkDBDoc(): Doc { return Cast(Doc.UserDoc().myLinkDatabase, Doc, null); }
-
- export function SetSelectedTool(tool: InkTool) { Doc.UserDoc().activeInkTool = tool; }
- export function GetSelectedTool(): InkTool { return StrCast(Doc.UserDoc().activeInkTool, InkTool.None) as InkTool; }
export function SetUserDoc(doc: Doc) { return (manager._user_doc = doc); }
const isSearchMatchCache = computedFn(function IsSearchMatch(doc: Doc) {
@@ -1060,31 +1057,31 @@ 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(container: Opt<Doc>, key: string, value: any, modifiers?: "remove" | "match" | "check" | "x" | undefined) {
+ // 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(container: Opt<Doc>, key: string, value: any, modifiers: "remove" | "match" | "check" | "x", toggle?: boolean, fieldSuffix?: string) {
if (!container) return;
- const docFilters = Cast(container._docFilters, listSpec("string"), []);
+ const filterField = "_" + (fieldSuffix ? fieldSuffix + "-" : "") + "docFilters";
+ const docFilters = Cast(container[filterField], 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);
+ container[filterField] = 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[filterField] = undefined;
+ } else if (modifiers !== "remove") {
+ docFilters.push(key + ":" + value + ":" + modifiers);
+ container[filterField] = new List<string>(docFilters);
}
});
}
@@ -1335,5 +1332,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); });