From a83ca2797da3f8fa0d7e9d5afe41822d4bc0d3ea Mon Sep 17 00:00:00 2001 From: n-gist <58081918+n-gist@users.noreply.github.com> Date: Thu, 10 Nov 2022 01:27:14 +0600 Subject: [PATCH] Lock SuggestOvertypingCapturer while suggest widget is active --- .../browser/suggestOvertypingCapturer.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/vs/editor/contrib/suggest/browser/suggestOvertypingCapturer.ts b/src/vs/editor/contrib/suggest/browser/suggestOvertypingCapturer.ts index 4a24f8807c1..a8f60b54fa9 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestOvertypingCapturer.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestOvertypingCapturer.ts @@ -13,15 +13,12 @@ export class OvertypingCapturer implements IDisposable { private readonly _disposables = new DisposableStore(); private _lastOvertyped: { value: string; multiline: boolean }[] = []; - private _empty: boolean = true; + private _locked: boolean = false; constructor(editor: ICodeEditor, suggestModel: SuggestModel) { this._disposables.add(editor.onWillType(() => { - if (!this._empty) { - return; - } - if (!editor.hasModel()) { + if (this._locked || !editor.hasModel()) { return; } @@ -37,6 +34,9 @@ export class OvertypingCapturer implements IDisposable { } } if (!willOvertype) { + if (this._lastOvertyped.length !== 0) { + this._lastOvertyped.length = 0; + } return; } @@ -50,18 +50,19 @@ export class OvertypingCapturer implements IDisposable { } this._lastOvertyped[i] = { value: model.getValueInRange(selection), multiline: selection.startLineNumber !== selection.endLineNumber }; } - this._empty = false; + })); + + this._disposables.add(suggestModel.onDidTrigger(e => { + this._locked = true; })); this._disposables.add(suggestModel.onDidCancel(e => { - if (!this._empty && !e.retrigger) { - this._empty = true; - } + this._locked = false; })); } getLastOvertypedInfo(idx: number): { value: string; multiline: boolean } | undefined { - if (!this._empty && idx >= 0 && idx < this._lastOvertyped.length) { + if (idx >= 0 && idx < this._lastOvertyped.length) { return this._lastOvertyped[idx]; } return undefined;