From 40f52d119be06b60515e5058607633409f847e4f Mon Sep 17 00:00:00 2001
From: 0x85FB9C51 <77808164+0x85FB9C51@users.noreply.github.com>
Date: Sat, 26 Jun 2021 17:15:59 -0400
Subject: numbers now recognized as numbers, other misc. bugfixes, some bugs
 remaining

---
 .../views/collections/CollectionSchemaCells.tsx    | 39 ++++++++++++++++------
 1 file changed, 29 insertions(+), 10 deletions(-)

(limited to 'src/client/views/collections/CollectionSchemaCells.tsx')

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));
                                         }
                                     }
-- 
cgit v1.2.3-70-g09d2

