Browse Source

Fix autocompletion issue described in #10118 (#10234)

Kevin Jahns 4 years ago
parent
commit
a1ec7bd163
1 changed files with 7 additions and 3 deletions
  1. 7 3
      packages/shared-models/src/ymodels.ts

+ 7 - 3
packages/shared-models/src/ymodels.ts

@@ -153,8 +153,10 @@ export class YFile
   public updateSource(start: number, end: number, value = ''): void {
     this.transact(() => {
       const ysource = this.ysource;
-      ysource.delete(start, end - start);
+      // insert and then delete.
+      // This ensures that the cursor position is adjusted after the replaced content.
       ysource.insert(start, value);
+      ysource.delete(start + value.length, end - start);
     });
   }
 
@@ -667,9 +669,11 @@ export class YBaseCell<Metadata extends models.ISharedBaseCellMetadata>
    */
   public updateSource(start: number, end: number, value = ''): void {
     this.transact(() => {
-      const ysource = this.ymodel.get('source');
-      ysource.delete(start, end - start);
+      const ysource = this.ysource;
+      // insert and then delete.
+      // This ensures that the cursor position is adjusted after the replaced content.
       ysource.insert(start, value);
+      ysource.delete(start + value.length, end - start);
     });
   }