aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0x85FB9C51 <77808164+0x85FB9C51@users.noreply.github.com>2021-06-26 17:15:59 -0400
committer0x85FB9C51 <77808164+0x85FB9C51@users.noreply.github.com>2021-06-26 17:15:59 -0400
commit40f52d119be06b60515e5058607633409f847e4f (patch)
treef16c3ec388fd1509d70e133a9a9e9732dfdb06ed
parent8937d756513cd918371664aad25a8a9fa41878d1 (diff)
numbers now recognized as numbers, other misc. bugfixes, some bugs remaining
-rw-r--r--src/client/util/Scripting.ts1
-rw-r--r--src/client/views/collections/CollectionSchemaCells.tsx39
2 files changed, 30 insertions, 10 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index c3c3083be..3fe14a2a4 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -268,6 +268,7 @@ function forEachNode(node: ts.Node, onEnter: Traverser, onExit?: Traverser, inde
export function CompileScript(script: string, options: ScriptOptions = {}): CompileResult {
const { requiredType = "", addReturn = false, params = {}, capturedVariables = {}, typecheck = true } = options;
+ console.log("options: " + options.requiredType, options.addReturn, options.params);
if (options.params && !options.params.this) options.params.this = Doc.name;
if (options.params && !options.params.self) options.params.self = Doc.name;
if (options.globals) {
diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx
index 045995faa..38b3b1628 100644
--- a/src/client/views/collections/CollectionSchemaCells.tsx
+++ b/src/client/views/collections/CollectionSchemaCells.tsx
@@ -243,37 +243,56 @@ export class CollectionSchemaCell extends React.Component<CellProps> {
const script = value.substring(value.startsWith("=:=") ? 3 : 2);
retVal = this.props.setComputed(script, value.startsWith(":=") ? this._rowDataDoc : this._rowDoc, this.renderFieldKey, this.props.row, this.props.col);
} else {
- const inputAsNum: number = parseInt(value);
// check if the input is a number
- if (isNaN(inputAsNum)) {
+ let inputIsNum = true;
+ for (let s of value) {
+ if (isNaN(parseInt(s))) {
+ inputIsNum = false;
+ }
+ console.log(inputIsNum);
+ }
+ console.log("value: " + value);
+ if (!inputIsNum && !value.startsWith("=")) {
+ console.log("I don't beep because I'm not a computer.");
// if it's not a number, it's a string, and should be processed as such
- //TODO: maake the input not "thing" when it is being edited
// strips the string of quotes when it is edited to prevent quotes form being added to the text automatically
// after each edit
let valueSansQuotes = value;
if (this._isEditing) {
- valueSansQuotes = valueSansQuotes.substring(1, valueSansQuotes.length - 1);
+ const vsqLength = valueSansQuotes.length;
+ // get rid of outer quotes
+ valueSansQuotes = valueSansQuotes.substring(value.startsWith("\"") ? 1 : 0,
+ valueSansQuotes.charAt(vsqLength - 1) == "\"" ? vsqLength - 1 : vsqLength);
}
- const inputscript = valueSansQuotes.substring(value.startsWith("=") ? 1 : 0);
let inputAsString = '"';
// escape any quotes in the string
- //TODO: remove this note to self: when the type is number, it behaves liek I want any to behave
- for (const i of inputscript) {
+ //TODO: remove this note to self: when the type is number, it behaves like I want any to behave
+ //TODO: fix type laziness
+ for (const i of valueSansQuotes) {
if (i == '"') {
inputAsString += '\\"';
} else {
inputAsString += i;
}
}
+ // add a closing quote
inputAsString += '"';
+ console.log(inputAsString);
//two options here: we can strip off outer quotes or we can figure out what's going on with the script
const script = CompileScript(inputAsString, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
- script.compiled && (retVal = this.applyToDoc(inputscript.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
+ script.compiled && (retVal = this.applyToDoc(valueSansQuotes.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
} else {
//TODO: make accept numbers
+ console.log("I beep because I'm a computer");
const inputscript = value.substring(value.startsWith("=") ? 1 : 0);
- const inputAsString = '"' + inputscript + '"';
- const script = CompileScript(inputscript, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
+ // if commas are not stripped, the parser only considers the numbers after the last comma
+ let inputSansCommas = "";
+ for (let s of inputscript) {
+ if (!(s == ",")) {
+ inputSansCommas += s;
+ }
+ }
+ const script = CompileScript(inputSansCommas, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } });
script.compiled && (retVal = this.applyToDoc(inputscript.length !== value.length ? this._rowDoc : this._rowDataDoc, this.props.row, this.props.col, script.run));
}
}