Skip to content

Commit

Permalink
Keep the same statusBar item when updating it to prevent flickering o…
Browse files Browse the repository at this point in the history
…f the status bar. (#1022)
  • Loading branch information
TheLapinMalin authored Mar 28, 2024
1 parent a5bfcfe commit 8b4469a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions extensions/vscode/src/autocomplete/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const statusBarItemText = (enabled: boolean | undefined) =>
const statusBarItemTooltip = (enabled: boolean | undefined) =>
enabled ? "Tab autocomplete is enabled" : "Click to enable tab autocomplete";

let lastStatusBar: vscode.StatusBarItem | undefined = undefined;
let statusBarItem: vscode.StatusBarItem | undefined = undefined;
let statusBarFalseTimeout: NodeJS.Timeout | undefined = undefined;

export function stopStatusBarLoading() {
Expand All @@ -24,27 +24,25 @@ export function setupStatusBar(
statusBarFalseTimeout = undefined;
}

const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
);
// If statusBarItem hasn't been defined yet, create it
if (!statusBarItem) {
statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
);
}

statusBarItem.text = loading
? "$(loading~spin) Continue"
: statusBarItemText(enabled);
statusBarItem.tooltip = statusBarItemTooltip(enabled);
statusBarItem.command = "continue.toggleTabAutocompleteEnabled";

// Swap out with old status bar
if (lastStatusBar) {
lastStatusBar.dispose();
}
statusBarItem.show();
lastStatusBar = statusBarItem;

vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("continue")) {
const config = vscode.workspace.getConfiguration("continue");
const enabled = config.get<boolean>("enableTabAutocomplete");
statusBarItem.dispose();
setupStatusBar(enabled);
}
});
Expand Down

0 comments on commit 8b4469a

Please sign in to comment.