Skip to content

Commit aadbe18

Browse files
authored
Merge pull request microsoft#165871 from n-gist/broken-snippet-overtyping-fix
Fix snippet overtyping feature
2 parents 643ac4e + a83ca27 commit aadbe18

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/vs/editor/contrib/suggest/browser/suggestOvertypingCapturer.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ export class OvertypingCapturer implements IDisposable {
1313
private readonly _disposables = new DisposableStore();
1414

1515
private _lastOvertyped: { value: string; multiline: boolean }[] = [];
16-
private _empty: boolean = true;
16+
private _locked: boolean = false;
1717

1818
constructor(editor: ICodeEditor, suggestModel: SuggestModel) {
1919

2020
this._disposables.add(editor.onWillType(() => {
21-
if (!this._empty) {
22-
return;
23-
}
24-
if (!editor.hasModel()) {
21+
if (this._locked || !editor.hasModel()) {
2522
return;
2623
}
2724

@@ -37,6 +34,9 @@ export class OvertypingCapturer implements IDisposable {
3734
}
3835
}
3936
if (!willOvertype) {
37+
if (this._lastOvertyped.length !== 0) {
38+
this._lastOvertyped.length = 0;
39+
}
4040
return;
4141
}
4242

@@ -50,18 +50,19 @@ export class OvertypingCapturer implements IDisposable {
5050
}
5151
this._lastOvertyped[i] = { value: model.getValueInRange(selection), multiline: selection.startLineNumber !== selection.endLineNumber };
5252
}
53-
this._empty = false;
53+
}));
54+
55+
this._disposables.add(suggestModel.onDidTrigger(e => {
56+
this._locked = true;
5457
}));
5558

5659
this._disposables.add(suggestModel.onDidCancel(e => {
57-
if (!this._empty && !e.retrigger) {
58-
this._empty = true;
59-
}
60+
this._locked = false;
6061
}));
6162
}
6263

6364
getLastOvertypedInfo(idx: number): { value: string; multiline: boolean } | undefined {
64-
if (!this._empty && idx >= 0 && idx < this._lastOvertyped.length) {
65+
if (idx >= 0 && idx < this._lastOvertyped.length) {
6566
return this._lastOvertyped[idx];
6667
}
6768
return undefined;

0 commit comments

Comments
 (0)