Skip to content

Commit

Permalink
Fixes #172142
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Jan 25, 2023
1 parent 88df431 commit a4de6ce
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { h } from 'vs/base/browser/dom';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { KeybindingLabel } from 'vs/base/browser/ui/keybindingLabel/keybindingLabel';
import { Action, IAction, Separator } from 'vs/base/common/actions';
import { RunOnceScheduler } from 'vs/base/common/async';
import { Codicon } from 'vs/base/common/codicons';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { OperatingSystem } from 'vs/base/common/platform';
Expand Down Expand Up @@ -132,6 +133,14 @@ export class InlineSuggestionHintsContentWidget extends Disposable implements IC
this._contextKeyService
));

private readonly clearAvailableSuggestionCountLabelDebounced = this._register(new RunOnceScheduler(() => {
this.availableSuggestionCountAction.label = '';
}, 100));

private readonly disableButtonsDebounced = this._register(new RunOnceScheduler(() => {
this.previousAction.enabled = this.nextAction.enabled = false;
}, 100));

constructor(
private readonly editor: ICodeEditor,
@ICommandService private readonly _commandService: ICommandService,
Expand Down Expand Up @@ -160,8 +169,19 @@ export class InlineSuggestionHintsContentWidget extends Disposable implements IC
public update(position: Position | null, currentSuggestionIdx: number, suggestionCount: number | undefined, extraCommands: Command[]): void {
this.position = position;

this.previousAction.enabled = this.nextAction.enabled = suggestionCount !== undefined && suggestionCount > 1;
this.availableSuggestionCountAction.label = suggestionCount !== undefined ? `${currentSuggestionIdx + 1}/${suggestionCount}` : '1/?';
if (suggestionCount !== undefined && suggestionCount > 1) {
this.disableButtonsDebounced.cancel();
this.previousAction.enabled = this.nextAction.enabled = true;
} else {
this.disableButtonsDebounced.schedule();
}

if (suggestionCount !== undefined) {
this.clearAvailableSuggestionCountLabelDebounced.cancel();
this.availableSuggestionCountAction.label = `${currentSuggestionIdx + 1}/${suggestionCount}`;
} else {
this.clearAvailableSuggestionCountLabelDebounced.schedule();
}

this.editor.layoutContentWidget(this);

Expand Down

0 comments on commit a4de6ce

Please sign in to comment.