diff options
-rw-r--r-- | src/client/views/collections/collectionSchema/SchemaCellField.tsx | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx index 9d9fcbd1f..84b4d3462 100644 --- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx +++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx @@ -45,6 +45,16 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro get docIndex(){return DocumentView.getDocViewIndex(this._props.Document);} // prettier-ignore + @computed get lastChar(){ + const text = this._unrenderedContent.slice(); + for (let i = text.length - 1; i > 0; --i) { + if (text.charCodeAt(i) !== 160 && text.charCodeAt(i) !== 32) { + return text[i]; + } + } + return null; + } + componentDidMount(): void { this._unrenderedContent = this._props.GetValue() ?? ''; this.setContent(this._unrenderedContent, true); @@ -94,10 +104,6 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro this.finalizeEdit(false, true, false); } - // @computed get lastChar(){ - // this. - // } - generateSpan = (text: string, cell: HTMLDivElement | undefined) => { return `<span style="color: ${cell?.style.borderTop.replace('2px solid', '')}">${text}</span>` } @@ -215,6 +221,9 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro this._unrenderedContent = targVal; this._props.highlightCells?.(targVal); if (this.shouldUpdate(prevVal, targVal)) {this.setContent(targVal, true)}; + console.log(this.lastChar === '+'); + if (this.lastChar === '+') this.setupRefSelect(true); + else this.setupRefSelect(false); }; setupRefSelect = (enabled: boolean) => { @@ -247,12 +256,8 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro case 'ArrowUp': case 'ArrowDown': case 'ArrowLeft': case 'ArrowRight': // prettier-ignore e.stopPropagation(); break; - case '+': case '*': case '/': case '%': // prettier-ignore - this.setupRefSelect(true); - break; case ' ': e.stopPropagation(); - console.log('deteected') let cursorPos = 0; if (this.cursorPosition !== null) cursorPos = this.cursorPosition + 1; setTimeout(() => { @@ -263,13 +268,11 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro break; case 'u': // for some reason 'u' otherwise exits the editor e.stopPropagation(); - this.setupRefSelect(false); break; case 'Shift': case 'Alt': case 'Meta': case 'Control': case ':': // prettier-ignore break; // eslint-disable-next-line no-fallthrough default: - this.setupRefSelect(false); break; } }; @@ -285,6 +288,7 @@ 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._props.SetValue(this._unrenderedContent, shiftDown, enterKey)) { this._editing = false; } else { |