Skip to content

Commit 96db79d

Browse files
committed
SingleUpdatedNextEdit: Correctly apply insertion changes
1 parent a9bcdfb commit 96db79d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/vs/editor/contrib/inlineCompletions/browser/model/inlineSuggestionItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ class SingleUpdatedNextEdit {
673673
if (isInsertion && !shouldPreserveEditShape && change.replaceRange.start === editStart && editReplaceText.startsWith(change.newText)) {
674674
editStart += change.newText.length;
675675
editReplaceText = editReplaceText.substring(change.newText.length);
676-
editEnd = Math.max(editStart, editEnd);
676+
editEnd += change.newText.length;
677677
editHasChanged = true;
678678
continue;
679679
}

src/vs/editor/contrib/inlineCompletions/test/browser/inlineEdits.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class Point {
1818
getLength2D(): number {
1919
return↓ Math.sqrt(this.x * this.x + this.y * this.y↓);
2020
}
21+
22+
getJson(): string {
23+
return ↓Ü;
24+
}
2125
}
2226
`);
2327

@@ -57,6 +61,10 @@ class Point {
5761
getLength3D(): number {
5862
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
5963
}
64+
65+
getJson(): string {
66+
return Ü;
67+
}
6068
}
6169
`);
6270
});
@@ -90,6 +98,24 @@ class Point {
9098
});
9199
});
92100

101+
test('Inline Edit Is Correctly Shifted When Typing', async () => {
102+
await runTest(async ({ context, model, editor, editorViewModel }, provider, view) => {
103+
provider.add(`Ü`, `{x: this.x, y: this.y}`);
104+
await model.trigger();
105+
await timeout(10000);
106+
assert.deepStrictEqual(view.getAndClearViewStates(), ([
107+
undefined,
108+
"...\n\t\treturn ❰Ü↦{x: t...is.y}❱;\n"
109+
]));
110+
editor.setPosition(val.getMarkerPosition(2));
111+
editorViewModel.type('{');
112+
113+
assert.deepStrictEqual(view.getAndClearViewStates(), ([
114+
"...\t\treturn {❰Ü↦x: th...is.y}❱;\n"
115+
]));
116+
});
117+
});
118+
93119
test('Inline Edit Stays On Unrelated Edit', async function () {
94120
await runTest(async ({ context, model, editor, editorViewModel }, provider, view) => {
95121
provider.add(`getLength2D(): number {

0 commit comments

Comments
 (0)