From 318398252568333da41426c8b2dbfe18be6e1c3f Mon Sep 17 00:00:00 2001 From: Jacob Kim Date: Wed, 25 Jun 2025 10:52:44 -0700 Subject: [PATCH] fix a bug where toggling the next edit settings sometimes won't do anything --- .../src/activation/NextEditWindowManager.ts | 55 +++++++++++-------- gui/src/pages/config/ContinueFeaturesMenu.tsx | 7 ++- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/extensions/vscode/src/activation/NextEditWindowManager.ts b/extensions/vscode/src/activation/NextEditWindowManager.ts index 90db6328c..bc78fc832 100644 --- a/extensions/vscode/src/activation/NextEditWindowManager.ts +++ b/extensions/vscode/src/activation/NextEditWindowManager.ts @@ -141,31 +141,33 @@ export class NextEditWindowManager { false, ); - const existingCommands = await vscode.commands.getCommands(); + // Helper function to register commands safely. + const registerCommandSafely = ( + commandId: string, + callback: () => Promise, + ) => { + try { + const command = vscode.commands.registerCommand(commandId, callback); + context.subscriptions.push(command); + } catch (error) { + console.log( + `Command ${commandId} already has an associated callback, skipping registration`, + ); + } + }; - if (!existingCommands.includes(HIDE_TOOLTIP_COMMAND)) { - // Register the command to hide tooltips - const hideTooltipsCommand = vscode.commands.registerCommand( - HIDE_TOOLTIP_COMMAND, - async () => { - await this.hideAllTooltips(); - }, - ); - context.subscriptions.push(hideTooltipsCommand); - } + // Register HIDE_TOOLTIP_COMMAND and ACCEPT_NEXT_EDIT_COMMAND + // with their corresponding callbacks. + registerCommandSafely( + HIDE_TOOLTIP_COMMAND, + async () => await this.hideAllTooltips(), + ); + registerCommandSafely( + ACCEPT_NEXT_EDIT_COMMAND, + async () => await this.acceptNextEdit(), + ); - if (!existingCommands.includes(ACCEPT_NEXT_EDIT_COMMAND)) { - // Register the command to accept next edit - const acceptNextEditCommand = vscode.commands.registerCommand( - ACCEPT_NEXT_EDIT_COMMAND, - () => { - this.acceptNextEdit(); - }, - ); - context.subscriptions.push(acceptNextEditCommand); - } - - // Add this class to context disposables + // Add this class to context disposables. context.subscriptions.push(this); if (textApplier) { @@ -222,6 +224,13 @@ export class NextEditWindowManager { "nextEditWindowActive", true, ); + + console.log( + await vscode.commands.executeCommand( + "getContext", + "nextEditWindowActive", + ), + ); } /** diff --git a/gui/src/pages/config/ContinueFeaturesMenu.tsx b/gui/src/pages/config/ContinueFeaturesMenu.tsx index b1810e23b..60ca8df85 100644 --- a/gui/src/pages/config/ContinueFeaturesMenu.tsx +++ b/gui/src/pages/config/ContinueFeaturesMenu.tsx @@ -18,8 +18,9 @@ export function ContinueFeaturesMenu({ const { session } = useAuth(); useEffect(() => { // Only run this effect when both optInNextEditFeature is true and session is available. - // This still sets up the next edit window manager when the user leaves the setting on - // before exiting vscode. + // This effectively handles cases where there user + // leaves the setting on before exiting vscode, + // which leaves the toggle to be on. if (optInNextEditFeature && session) { const continueEmail = (session as HubSessionInfo)?.account?.id ?? null; if (continueEmail) { @@ -35,7 +36,7 @@ export function ContinueFeaturesMenu({ handleUpdate({ optInNextEditFeature: value, }); - // Send message to VSCode extension with the email + // Send message to VSCode extension with the email. const continueEmail = (session as HubSessionInfo)?.account?.id ?? null; if (continueEmail) { ideMessenger.post("optInNextEditFeature", {