Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

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 CloseWebviewEditorAction that intercepts CMD-W for webview editors:

  • Keybinding registration: CMD-W (CMD-F4 on Windows) with KeybindingWeight.EditorContrib + 1 priority
  • Context guard: Only activates when webviewActiveContextKeyExpr is true
  • Isolated close: Calls group.closeEditor(activeEditor) for the webview only

The higher weight ensures this runs before the default close command, preventing cascade to parent editors.

Changes

  • src/vs/workbench/contrib/webviewPanel/browser/webviewCommands.ts: Added CloseWebviewEditorAction class
  • src/vs/workbench/contrib/webviewPanel/browser/webviewPanel.contribution.ts: Registered the action

Related 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
Item Value
CPUs Apple M1 Max (10 x 2400)
GPU Status 2d_canvas: enabled
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
Load (avg) 5, 7, 8
Memory (System) 64.00GB (0.28GB free)
Process Argv --crash-reporter-id 32508526-d220-467e-9fc6-305c7843eb7d
Screen Reader no
VM 0%
Extensions (58)
Extension Author (truncated) Version
better-comments aar 3.0.2
protein-viewer Ari 0.1.0
zoterolatex bna 0.4.1
doxdocgen csc 1.4.0
vscode-markdownlint Dav 0.60.0
gitlens eam 17.3.1
copilot Git 1.344.0
copilot-chat Git 0.29.1
vscode-pull-request-github Git 0.114.1
gc-excelviewer Gra 4.2.63
ai-docstring gra 0.1.3
vscode-h5web h5w 0.1.9
latex-workshop Jam 10.10.0
better-cpp-syntax jef 1.27.1
snipped jef 1.3.0
cmake-language-support-vscode jos 0.0.9
vsc-python-indent Kev 1.21.0
rainbow-csv mec 3.20.0
vscode-dotnet-runtime ms- 2.3.6
black-formatter ms- 2025.2.0
debugpy ms- 2025.11.2025070101
flake8 ms- 2025.2.0
isort ms- 2025.0.0
pylint ms- 2025.2.0
python ms- 2025.11.2025071501
vscode-pylance ms- 2025.6.2
vscode-python-envs ms- 0.3.11971010
jupyter ms- 2025.6.0
jupyter-hub ms- 2024.5.1002432242
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.3.0
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
remote-containers ms- 0.422.1
remote-ssh ms- 0.120.0
remote-ssh-edit ms- 0.87.0
remote-wsl ms- 0.99.0
cmake-tools ms- 1.21.36
cpptools ms- 1.26.3
cpptools-extension-pack ms- 1.3.1
remote-explorer ms- 0.5.0
autodocstring njp 0.6.1
vscode-python-typehint njq 1.5.1
indent-rainbow ode 8.3.1
platformio-ide pla 3.3.4
vscode-wl shi 1.7.3
rewrap stk 1.16.3
code-spell-checker str 4.0.47
code-spell-checker-german str 2.3.3
cif thi 1.0.0
shellcheck tim 0.38.1
pdf tom 1.2.2
cmake twx 0.0.17
errorlens use 3.26.0
volar Vue 3.0.1
maple yjt 1.2.8
markdown-pdf yza 1.5.0
markdown-all-in-one yzh 3.6.3

(1 theme extensions excluded)

A/B Experiments
vsliv368:30146709
binariesv615:30325510
962ge761:31349326
h48ei257:31000450
nativeloc1:31344060
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
9064b325:31222308
copilot_t_ci:31333650
e5gg6876:31282496
pythoneinst12:31285622
c7cif404:31314491
pythonpulldiag:31343502
996jf627:31283433
pythonrdcb7:31342333
usemplatestapi:31297334
0aa6g176:31307128
747dc170:31275177
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
9d2cg352:31346308
usemarketplace:31343026
nesew2to5:31336538
agentclaude:31335815
b6b4d950:31327385
nes-diff-11:31337487
498jd511-mono:31348501
66g5g415:31348965
nes-set-on:31349227
63221493:31336333
yijiwantestdri0626-c:31336931
64bie973:31349831
4gdec884:31348710
editstats-enabled:31346257

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.

Copilot AI changed the title [WIP] Fix CMD-W closing figure and jupyter notebook Fix CMD-W closing webview editor and parent editor together Dec 10, 2025
Copilot AI requested a review from DonJayamanne December 10, 2025 03:14
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.

CMD-W closes figure and jupyter notebook

2 participants