From c472f9844ed2806f7965713cf618363210e37de1 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Sat, 15 Jun 2024 00:08:00 -0400
Subject: text highlighting works with 'this.' format

---
 .../collectionSchema/SchemaTableCell.tsx           | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 deletions(-)

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

diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
index 26dc9c3c2..69880b280 100644
--- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
@@ -81,13 +81,11 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
         makeObservable(this);
     }
 
-    get isDefault(){
-        return SchemaColumnHeader.isDefaultField(this._props.fieldKey);
-    }
+    get docIndex(){return DocumentView.getDocViewIndex(this._props.Document);} // prettier-ignore
 
-    get lockedInteraction(){
-        return (this.isDefault || this._props.Document._lockedSchemaEditing);
-    }
+    get isDefault(){return SchemaColumnHeader.isDefaultField(this._props.fieldKey);} // prettier-ignore
+
+    get lockedInteraction(){return (this.isDefault || this._props.Document._lockedSchemaEditing);} // prettier-ignore
 
     get backgroundColor(){
         if (this.lockedInteraction){
@@ -141,13 +139,12 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
         const pointerEvents: 'all' | 'none' = !readOnly && isRowActive() ? 'all' : 'none';
         return { color, textDecoration, fieldProps, cursor, pointerEvents };
     }
-
-    // openContextMenu = () => {
-    //     const cm = ContextMenu.Instance;
-    //     cm.clearItems();
-
         
-    // }
+    adjustedHighlight = (field: string) => {
+        const pattern = /\bthis.\b/g;  
+        const modField = field.replace(pattern, `d${this.docIndex}.`);
+        this._props.highlightCells(modField);
+    }
 
     // parses a field from the "idToDoc(####)" format to DocumentId (d#) format for readability
     cleanupField = (field: string) => {
@@ -158,6 +155,11 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
         while ((matches = idPattern.exec(field)) !== null) {results.push([matches[0], matches[1].replace(/"/g, '')]); }
         results.forEach((idFuncPair) => {modField = modField.replace(idFuncPair[0], 'd' + (DocumentView.getDocViewIndex(IdToDoc(idFuncPair[1]))).toString());})
         if (modField.charAt(modField.length - 1) === ';') modField = modField.substring(0, modField.length - 1);
+        
+        const selfRefPattern = `d${this.docIndex}.${this._props.fieldKey}`
+        const selfRefRegX = RegExp(selfRefPattern, 'g');
+        if (selfRefRegX.exec(modField) !== null) { return 'Invalid'}
+
         return modField;
     }
 
@@ -175,7 +177,7 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
                     pointerEvents: this.lockedInteraction ? 'none' : pointerEvents,
                 }}>
                 <EditableView
-                    highlightCells={this._props.highlightCells}
+                    highlightCells={this.adjustedHighlight}
                     ref={r => selectedCell(this._props) && this._props.autoFocus && r?.setIsFocused(true)}
                     oneLine={this._props.oneLine}
                     allowCRs={this._props.allowCRs}
-- 
cgit v1.2.3-70-g09d2

