Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 28, 2025

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:

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:

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

Firewall rules blocked me from connecting to one or more addresses

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:


💡 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 in the docs.

@Copilot Copilot AI changed the title [WIP] Histogram in VS Code is not cancelled by pressing Escape when prompted for the number of shots Fix histogram escape key handling in VS Code extension May 28, 2025
@Copilot Copilot AI requested a review from minestarks May 28, 2025 20:04
Copilot finished work on behalf of minestarks May 28, 2025 20:04
@minestarks minestarks marked this pull request as ready for review May 28, 2025 20:24
@minestarks minestarks requested review from billti and idavis as code owners May 28, 2025 20:24
@minestarks minestarks added this pull request to the merge queue May 28, 2025
Merged via the queue into main with commit 9f6b911 May 29, 2025
21 of 35 checks passed
@minestarks minestarks deleted the copilot/fix-1872 branch May 29, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Histogram in VS Code is not cancelled by pressing Escape when prompted for the number of shots
3 participants