diff options
-rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 4 | ||||
-rw-r--r-- | src/client/views/collections/collectionSchema/SchemaCellField.tsx | 22 |
2 files changed, 15 insertions, 11 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 583829d6c..57327a008 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -206,7 +206,7 @@ export class CollectionSchemaView extends CollectionSubView() { ) this._disposers.sortHighlight = reaction( () => [this.sortField, this._docs, this._selectedDocs, this._highlightedCellsInfo], - () => {this.sortField && setTimeout(() => this.highlightSortedColumn(), 0)}, + () => {this.sortField && setTimeout(() => this.highlightSortedColumn())}, {fireImmediately: true} ) } @@ -505,7 +505,7 @@ export class CollectionSchemaView extends CollectionSubView() { if (field || this.sortField){ index = this.columnKeys.indexOf(field || this.sortField); const increment: number = 100/rowCount; - for (let i = 0; i < rowCount; ++i){ + for (let i = 1; i <= rowCount; ++i){ const adjColor = ClientUtils.lightenRGB(16, 66, 230, increment * i); highlightColors.push(`solid 2px rgb(${adjColor[0]}, ${adjColor[1]}, ${adjColor[2]})`); } diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx index 7bdfaa587..8e751f4ba 100644 --- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx +++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx @@ -40,11 +40,13 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro setTimeout(() => { this._unrenderedContent = this._props.GetValue() ?? ''; this.setContent(this._unrenderedContent); - }, 0); //must be moved to end of batch or else other docs aren't loaded, so render as d-1 in function + }); //must be moved to end of batch or else other docs aren't loaded, so render as d-1 in function } get docIndex(){return DocumentView.getDocViewIndex(this._props.Document);} // prettier-ignore + get selfRefPattern() {return `d${this.docIndex}.${this._props.fieldKey}`}; + @computed get lastCharBeforeCursor(){ const pos = this.cursorPosition; const content = this._unrenderedContent; @@ -76,7 +78,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro this._overlayDisposer = OverlayView.Instance.addElement(<DocumentIconContainer />, { x: 0, y: 0 }); this._props.highlightCells?.(this._unrenderedContent); this.setContent(this._unrenderedContent); - setTimeout(() => this.setCursorPosition(this._unrenderedContent.length), 0); + setTimeout(() => this.setCursorPosition(this._unrenderedContent.length)); } }); } else { @@ -114,7 +116,8 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro } generateSpan = (text: string, cell: HTMLDivElement | undefined) => { - return `<span style="color: ${cell?.style.borderTop.replace('2px solid', '')}">${text}</span>` + const selfRef = text === this.selfRefPattern; + return `<span style="text-decoration: ${selfRef ? 'underline' : 'none'}; text-decoration-color: red; color: ${selfRef ? 'gray' : cell?.style.borderTop.replace('2px solid', '')}">${text}</span>`; } makeSpans = (content: string) => { @@ -147,7 +150,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro setContent = (content: string, restoreCursorPos?: boolean) => { const pos = this.cursorPosition; this._displayedContent = this.makeSpans(content); - restoreCursorPos && setTimeout(() => this.setCursorPosition(pos), 0); + restoreCursorPos && setTimeout(() => this.setCursorPosition(pos)); } @action @@ -157,7 +160,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro const robustPos = cursorPos ?? content.length; const newText = atCursorPos ? content.slice(0, robustPos) + text + content.slice(cursorPos ?? content.length) : this._unrenderedContent.concat(text); this.onChange(undefined, newText); - setTimeout(() => this.setCursorPosition(robustPos + text.length), 0); + setTimeout(() => this.setCursorPosition(robustPos + text.length)); } @action @@ -219,7 +222,6 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro }; onChange = (e: FormEvent<HTMLDivElement> | undefined, newText?: string) => { - console.log('onchange called') const prevVal = this._unrenderedContent; const targVal = newText ?? e!.currentTarget.innerText; // TODO: bang if (!(targVal.startsWith(':=') || targVal.startsWith('='))) { @@ -231,7 +233,6 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro this._unrenderedContent = targVal; this._props.highlightCells?.(targVal); if (this.shouldUpdate(prevVal, targVal)) {this.setContent(targVal, true)}; - console.log('cursorpos: ' + this.cursorPosition + ' char: ' + this.lastCharBeforeCursor); this.setupRefSelect(this.refSelectConditionMet); }; @@ -272,7 +273,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro if (this.cursorPosition !== null) cursorPos = this.cursorPosition + 1; setTimeout(() => { this.setContent(this._unrenderedContent); - setTimeout(() => this.setCursorPosition(cursorPos), 0); + setTimeout(() => this.setCursorPosition(cursorPos)); } , 0); break; @@ -298,7 +299,10 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro @action finalizeEdit(shiftDown: boolean, lostFocus: boolean, enterKey: boolean) { - // while (this.lastChar === '+') { this._unrenderedContent = this._unrenderedContent.slice(0, -1); } + if (this._unrenderedContent.replace(this.selfRefPattern, '') !== this._unrenderedContent) { + console.log('error'); this._editing = false; return; + } + if (this._props.SetValue(this._unrenderedContent, shiftDown, enterKey)) { this._editing = false; } else { |