Fix CMD-W closing webview editor and parent editor together #282385
+34
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When a webview editor (e.g., matplotlib figure from Jupyter notebook) is focused and CMD-W is pressed, both the webview and its parent editor close instead of just the webview.
The default close editor command lacks webview-specific handling. Added
CloseWebviewEditorActionthat intercepts CMD-W for webview editors:KeybindingWeight.EditorContrib + 1prioritywebviewActiveContextKeyExpris truegroup.closeEditor(activeEditor)for the webview onlyThe higher weight ensures this runs before the default close command, preventing cascade to parent editors.
Changes
src/vs/workbench/contrib/webviewPanel/browser/webviewCommands.ts: AddedCloseWebviewEditorActionclasssrc/vs/workbench/contrib/webviewPanel/browser/webviewPanel.contribution.ts: Registered the actionRelated Issues
Addresses issue where matplotlib widget figures in Jupyter notebooks close both the figure tab and notebook on CMD-W.
Original prompt
This section details on the original issue you should resolve
<issue_title>CMD-W closes figure and jupyter notebook</issue_title>
<issue_description>
Type: Bug
When I use the save-figure button in a python jupyter notebook with the %matplotlib widget the figure opens as a new tab. When I then press CMD-W to close the figure, the figure as well as the jupyter notebook closes.
The expected behavior is that only the figure tab closes.
VS Code version: Code 1.102.0 (cb0c47c, 2025-07-09T22:10:34.600Z)
OS version: Darwin arm64 22.6.0
Modes:
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: enabled_on
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Extensions (58)
(1 theme extensions excluded)
A/B Experiments
Comments on the Issue (you are @copilot in this section)
@DonJayamanne Thank you for filing this issue, I've tried this at my end and am unable to repro this issue. Please can you share a screen recording of this issue using a tool such as https://gifcap.dev @DonJayamanne I'm sorry for never getting back to you on this. Are you still running into this issue? @DonJayamanne Please can you disable all extensions except for jupyter related extension from Microsoft and try again @DonJayamanne @mjbvz Is this something to do with webviews, as Jupyter extension doesn't handle Ctrl+W explicitly. @mjbvz @DonJayamanne Probably but assigning back to you as our notebook support would need to implement the fix💡 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.