aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-06-25 12:26:00 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-06-25 12:26:00 -0400
commitaad1ca740bcbad129dc23a5d8f71e3caae787d43 (patch)
tree9ee263bcb130dcd42fe161822a22a103862db98c
parent54559c677ac3a91e72680b5b7c889d63439edf58 (diff)
cursor position reset properly, appendtext has atCursor option
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx2
-rw-r--r--src/client/views/collections/collectionSchema/SchemaCellField.tsx20
2 files changed, 14 insertions, 8 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 3b5a32ca7..32106e3be 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -658,7 +658,7 @@ export class CollectionSchemaView extends CollectionSubView() {
const field = this.columnKeys[col];
const refToAdd = `d${docIndex}.${field}`
const editedField = this._referenceSelectMode.currEditing ? this._referenceSelectMode.currEditing as SchemaCellField : null;
- editedField?.appendText(refToAdd);
+ editedField?.appendText(refToAdd, true);
editedField?.setupRefSelect(false);
return;
}
diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
index 06d3926a8..8c4c1cd76 100644
--- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
@@ -45,8 +45,10 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
get docIndex(){return DocumentView.getDocViewIndex(this._props.Document);} // prettier-ignore
- @computed get lastChar(){
- const text = this._unrenderedContent.slice();
+ @computed get lastCharBeforeCursor(){
+ const pos = this.cursorPosition;
+ const content = this._unrenderedContent;
+ const text = this._unrenderedContent.substring(0, pos ?? content.length);
for (let i = text.length - 1; i > 0; --i) {
if (text.charCodeAt(i) !== 160 && text.charCodeAt(i) !== 32) {
return text[i];
@@ -62,7 +64,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
() => this._editing,
editing => {
if (editing) {
- if (this.lastChar !== '+') this.setupRefSelect(false);
+ if (this.lastCharBeforeCursor !== '+') this.setupRefSelect(false);
setTimeout(() => {
if (this._inputref?.innerText.startsWith('=') || this._inputref?.innerText.startsWith(':=')) {
this._overlayDisposer?.();
@@ -145,9 +147,13 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
}
@action
- appendText = (text: string) => {
- const newText = this._unrenderedContent.concat(text);
+ appendText = (text: string, atCursorPos?: boolean) => {
+ const content = this._unrenderedContent;
+ const cursorPos = this.cursorPosition;
+ 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);
}
@action
@@ -222,8 +228,8 @@ 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);
+ console.log(this.lastCharBeforeCursor === '+');
+ if (this.lastCharBeforeCursor === '+') this.setupRefSelect(true);
else this.setupRefSelect(false);
};