aboutsummaryrefslogtreecommitdiff
path: root/src/fields/ScriptField.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2022-08-25 11:06:38 -0400
committerbobzel <zzzman@gmail.com>2022-08-25 11:06:38 -0400
commit0ed7131587c6739483da64a93d9f2ab6fdfbc15a (patch)
tree62190ade864e0cd55424b26792e01961a96ea1a6 /src/fields/ScriptField.ts
parentb8ebc0f758d2240af29640d6f8dc490705b42bb9 (diff)
fixed crashes in notetaking view and cleaned up code a bit. fixed undo of column deletion.
Diffstat (limited to 'src/fields/ScriptField.ts')
-rw-r--r--src/fields/ScriptField.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index 48d5c5563..d38a019b3 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -189,13 +189,13 @@ export class ComputedField extends ScriptField {
const compiled = ScriptField.CompileScript(script, params, true, capturedVariables);
return compiled.compiled ? new ComputedField(compiled) : undefined;
}
- public static MakeInterpolatedNumber(fieldKey: string, interpolatorKey: string, doc: Doc, curTimecode: number) {
+ public static MakeInterpolatedNumber(fieldKey: string, interpolatorKey: string, doc: Doc, curTimecode: number, defaultVal: Opt<number>) {
if (!doc[`${fieldKey}-indexed`]) {
const flist = new List<number>(numberRange(curTimecode + 1).map(i => undefined) as any as number[]);
- flist[curTimecode] = NumCast(doc[fieldKey]);
+ flist[curTimecode] = Cast(doc[fieldKey], 'number', null);
doc[`${fieldKey}-indexed`] = flist;
}
- const getField = ScriptField.CompileScript(`getIndexVal(self['${fieldKey}-indexed'], self.${interpolatorKey})`, {}, true, {});
+ const getField = ScriptField.CompileScript(`getIndexVal(self['${fieldKey}-indexed'], self.${interpolatorKey}, ${defaultVal})`, {}, true, {});
const setField = ScriptField.CompileScript(`setIndexVal(self['${fieldKey}-indexed'], self.${interpolatorKey}, value)`, { value: 'any' }, true, {});
return getField.compiled ? new ComputedField(getField, setField?.compiled ? setField : undefined) : undefined;
}
@@ -260,8 +260,8 @@ ScriptingGlobals.add(
);
ScriptingGlobals.add(
- function getIndexVal(list: any[], index: number) {
- return list?.reduce((p, x, i) => ((i <= index && x !== undefined) || p === undefined ? x : p), undefined as any);
+ function getIndexVal(list: any[], index: number, defaultVal: Opt<number> = undefined) {
+ return list?.reduce((p, x, i) => ((i <= index && x !== undefined) || p === undefined ? x : p), defaultVal);
},
'returns the value at a given index of a list',
'(list: any[], index: number)'