aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx3
-rw-r--r--src/client/views/collections/collectionSchema/SchemaCellField.tsx28
2 files changed, 14 insertions, 17 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 32106e3be..583829d6c 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -296,7 +296,6 @@ export class CollectionSchemaView extends CollectionSubView() {
break;
}
case 'P': {
- console.log(this._cellHighlightColors)
break;
}
default:
@@ -687,14 +686,12 @@ export class CollectionSchemaView extends CollectionSubView() {
@action
deselectCell = (doc: Doc) => {
- console.log('single deselect called')
this._selectedCells && (this._selectedCells = this._selectedCells.filter(d => d !== doc));
if (this.rowIndex(doc) === this._lowestSelectedIndex) this._lowestSelectedIndex = Math.min(...this._selectedDocs.map(d => this.rowIndex(d)));
};
@action
deselectAllCells = () => {
- console.log('deselectall called')
this._selectedCells = [];
this._lowestSelectedIndex = -1;
};
diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
index 8c4c1cd76..72d89adc3 100644
--- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
@@ -57,6 +57,11 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
return null;
}
+ @computed get refSelectConditionMet() {
+ const char = this.lastCharBeforeCursor;
+ return char === '+' || char === '*' || char === '/' || char === '%' || char === '=';
+ }
+
componentDidMount(): void {
this._unrenderedContent = this._props.GetValue() ?? '';
this.setContent(this._unrenderedContent, true);
@@ -64,13 +69,14 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
() => this._editing,
editing => {
if (editing) {
- if (this.lastCharBeforeCursor !== '+') this.setupRefSelect(false);
+ this.setupRefSelect(this.refSelectConditionMet);
setTimeout(() => {
if (this._inputref?.innerText.startsWith('=') || this._inputref?.innerText.startsWith(':=')) {
this._overlayDisposer?.();
this._overlayDisposer = OverlayView.Instance.addElement(<DocumentIconContainer />, { x: 0, y: 0 });
this._props.highlightCells?.(this._unrenderedContent);
- this.setContent(this._unrenderedContent, true);
+ this.setContent(this._unrenderedContent);
+ setTimeout(() => this.setCursorPosition(this._unrenderedContent.length), 0);
}
});
} else {
@@ -139,11 +145,9 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
@action
setContent = (content: string, restoreCursorPos?: boolean) => {
+ const pos = this.cursorPosition;
this._displayedContent = this.makeSpans(content);
- if (restoreCursorPos) {
- const cursorPos = this.cursorPosition;
- setTimeout(() => this.restoreCursorPosition(cursorPos), 0);
- }
+ restoreCursorPos && setTimeout(() => this.setCursorPosition(pos), 0);
}
@action
@@ -153,7 +157,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.restoreCursorPosition(robustPos + text.length), 0);
+ setTimeout(() => this.setCursorPosition(robustPos + text.length), 0);
}
@action
@@ -173,12 +177,10 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
adjRange.selectNodeContents(this._inputref);
adjRange.setEnd(range.startContainer, range.startOffset);
- console.log(adjRange.toString().length)
-
return adjRange.toString().length;
}
- restoreCursorPosition = (position: number | null) => {
+ setCursorPosition = (position: number | null) => {
const selection = window.getSelection();
if (!selection || position === null || !this._inputref) return;
@@ -228,9 +230,7 @@ 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.lastCharBeforeCursor === '+');
- if (this.lastCharBeforeCursor === '+') this.setupRefSelect(true);
- else this.setupRefSelect(false);
+ this.setupRefSelect(this.refSelectConditionMet);
};
setupRefSelect = (enabled: boolean) => {
@@ -269,7 +269,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
if (this.cursorPosition !== null) cursorPos = this.cursorPosition + 1;
setTimeout(() => {
this.setContent(this._unrenderedContent);
- setTimeout(() => this.restoreCursorPosition(cursorPos), 0);
+ setTimeout(() => this.setCursorPosition(cursorPos), 0);
}
, 0);
break;