Skip to content

Commit 9f6b911

Browse files
Copilotminestarks
andauthored
Fix histogram escape key handling in VS Code extension (#2468)
When users clicked "Histogram" in VS Code and were prompted for the number of shots, pressing Escape did not cancel the operation as expected. Instead, the histogram was still displayed with a default value of 100 shots. ## Root Cause The issue was in the `handleShowHistogram` function in `webviewPanel.ts`. The code used a fallback pattern that prevented proper escape key detection: ```typescript const numberOfShots = (await window.showInputBox({ value: "100", prompt: "Number of shots", validateInput: validateShotsInput, })) || "100"; // This check never worked because of the fallback above if (numberOfShots === undefined) { return; } ``` When a user pressed Escape, `showInputBox()` returned `undefined`, but the `|| "100"` fallback immediately assigned "100" to `numberOfShots`, making the subsequent `undefined` check never true. ## Solution Removed the problematic fallback and properly checked for escape key before using the input value: ```typescript const numberOfShotsInput = await window.showInputBox({ value: "100", prompt: "Number of shots", validateInput: validateShotsInput, }); // Now this properly detects when user presses Escape if (numberOfShotsInput === undefined) { return; } const numberOfShots = numberOfShotsInput; ``` This pattern matches how escape key handling is implemented correctly in other parts of the codebase, such as the Azure workspace actions and the resource estimation commands. ## Testing - ✅ VS Code extension builds successfully - ✅ TypeScript compilation passes - ✅ Linting and formatting checks pass - ✅ No unrelated files modified Fixes #1872. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `update.code.visualstudio.com` > - Triggering command: `node ./test/runTests.mjs ` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to my [firewall allow list](https://gh.io/copilot/firewall-config) > > </details> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: minestarks <[email protected]>
1 parent f7569f4 commit 9f6b911

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

vscode/src/webviewPanel.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,19 @@ export function registerWebViewCommands(context: ExtensionContext) {
104104
}
105105
};
106106

107-
const numberOfShots =
108-
(await window.showInputBox({
109-
value: "100",
110-
prompt: "Number of shots",
111-
validateInput: validateShotsInput,
112-
})) || "100";
107+
const numberOfShotsInput = await window.showInputBox({
108+
value: "100",
109+
prompt: "Number of shots",
110+
validateInput: validateShotsInput,
111+
});
113112

114113
// abort if the user hits <Esc> during shots entry
115-
if (numberOfShots === undefined) {
114+
if (numberOfShotsInput === undefined) {
116115
return;
117116
}
118117

118+
const numberOfShots = numberOfShotsInput;
119+
119120
sendMessageToPanel(
120121
{ panelType: "histogram", id: panelId },
121122
true,

0 commit comments

Comments
 (0)