vscode: Context-Menu COPY is not working in vscode webview, BUT ctrl+c is working fine
Issue Type: Bug
Use Case 1:
- Install an extension that uses a Webview (Oracle Developer Tool for VS Code)
- Connect to a Database
- Run any SELECT query
- In Result Tab, we can see the SQL Query that we just ran + Query Result
- Select the SQL Query Text >> Right Click >> COPY
- Paste in any text editor
Expected Result: Text is getting copied to text editor Actual Result: Text is not getting copied to text editor
Use Case 2:
- Install an extension that uses a Webview (Oracle Developer Tool for VS Code)
- Connect to a Database
- Run any SELECT query
- In Result Tab, we can see the SQL Query that we just ran + Query Result
- Select the SQL Query Text >> Press Ctrl+C
- Paste in any text editor
Expected Result: Text is getting copied to text editor Actual Result: Text is getting copied to text editor
VS Code version: Code 1.63.2 (899d46d82c4c95423fb7e10e68eba52050e30ba3, 2021-12-15T09:40:02.816Z) OS version: Windows_NT x64 10.0.18363 Restricted Mode: No
System Info
Item | Value |
---|---|
CPUs | Intel Xeon E3-12xx v2 (Ivy Bridge, IBRS) (2 x 2693) |
GPU Status | 2d_canvas: unavailable_software gpu_compositing: disabled_software multiple_raster_threads: disabled_off oop_rasterization: disabled_off opengl: disabled_off rasterization: disabled_software skia_renderer: enabled_on video_decode: disabled_software vulkan: disabled_off webgl: unavailable_software webgl2: unavailable_software |
Load (avg) | undefined |
Memory (System) | 14.65GB (8.33GB free) |
Process Argv | . --crash-reporter-id 699fa828-d5c2-42a4-95b5-df472e05dbaf |
Screen Reader | no |
VM | 0% |
Extensions (1)
Extension | Author (truncated) | Version |
---|---|---|
oracledevtools | Ora | 21.3.0 |
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30422343
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30424896
pythonvs932:30410667
vscop804:30404766
vscop453:30404998
vsrem710cf:30416617
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 30
- Comments: 18 (6 by maintainers)
@mjbvz I found the cause of the problem. When we right-click on the webview, the right-click menu that appears is actually provided by vscode (not webview), and webview mistakenly regarded this situation as losing focus. When the callback function of the copy command is executed, the activeWebview value cannot be obtained, so no operation is done.
When the right-click menu appears, onBlur is executed.
The error caused vscode to think that there was no webview in the active state at this time.
https://github.com/microsoft/vscode/blob/00abefa3e27ee1866cf6a6ac825578c1ddafd32c/src/vs/workbench/contrib/webview/browser/webview.contribution.ts#L22~L38
The context menu copy function is not working
Does this issue occur when all extensions are disabled?: Yes/No Yes
VS Code Version: 1.78.2 OS Version: Windows 11 Pro 22H2
Steps to Reproduce:
Please watch the video.
https://github.com/microsoft/vscode/assets/109512933/7cedd1c7-0b0d-47e8-87b3-e82fe9cefec2
I have the exact inverse problem in my extension on MacOS (right click copy is working fine, but cmd+c does not work)
Logan and I ran into this in the hex editor today as well.
@mjbvz , we have already looked into the sample code. In fact, we made the below change in the html returned from _getHtmlForWebview method like below:
Original Code:
Replaced with
After making the change, we tried to copy the text using context menu from the Webview but text is not getting copied.
Should we remove the “copy” context menu action until it’s working? It’s rather misleading at the moment.
I’m also seeing this issue with a web view on our extension. It’s really weird, Ctrl+C works perfectly fine, but right-click -> copy does not copy to the clipboard.
I found this, and I think this might be related to the issue:
https://stackoverflow.com/questions/70788421/context-menu-copy-is-not-working-in-vscode-webview-but-ctrlc-is-working-fine
A user replicated this issue while debugging vscode and found out that CTRL+C and right-click->Copy have different implementations.
Does anyone know if there is a workaround for this? Or if there’ll be a resolution soon?
Thanks!
Also, please let us know if there is any way to disable/greyed-out CUT/PASTE item in context menu. We just need the COPY item in the context menu.
@mjbvz this issue happens on both Windows as well as on Ubuntu. Text is not copied to clipboard. It would be a really breeze to use on cases where it’s easier to read and copy data from a markdown table for use in an another tool.
For example, I want to copy docker image sizes from a markdown file, while previewing it. Image attached below: