From 7d546de485678489e281c7d45dfe4391a8ee5a9f Mon Sep 17 00:00:00 2001 From: LapinMalin Date: Tue, 26 Mar 2024 01:49:50 +0100 Subject: [PATCH] Keep the same statusBar item when updating it to prevent flickering of the status bar. --- .../vscode/src/autocomplete/statusBar.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/extensions/vscode/src/autocomplete/statusBar.ts b/extensions/vscode/src/autocomplete/statusBar.ts index 28bf2b9b7b..07dcb8f16d 100644 --- a/extensions/vscode/src/autocomplete/statusBar.ts +++ b/extensions/vscode/src/autocomplete/statusBar.ts @@ -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() { @@ -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("enableTabAutocomplete"); - statusBarItem.dispose(); setupStatusBar(enabled); } });