Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context-Menu COPY is not working in vscode webview, BUT ctrl+c is working fine #141080

Closed
soumasar010322 opened this issue Jan 20, 2022 · 18 comments · Fixed by #206529
Closed

Context-Menu COPY is not working in vscode webview, BUT ctrl+c is working fine #141080

soumasar010322 opened this issue Jan 20, 2022 · 18 comments · Fixed by #206529
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders verified Verification succeeded webview Webview issues
Milestone

Comments

@soumasar010322
Copy link

Issue Type: Bug

Use Case 1:

  1. Install an extension that uses a Webview (Oracle Developer Tool for VS Code)
  2. Connect to a Database
  3. Run any SELECT query
  4. In Result Tab, we can see the SQL Query that we just ran + Query Result
  5. Select the SQL Query Text >> Right Click >> COPY
  6. 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:

  1. Install an extension that uses a Webview (Oracle Developer Tool for VS Code)
  2. Connect to a Database
  3. Run any SELECT query
  4. In Result Tab, we can see the SQL Query that we just ran + Query Result
  5. Select the SQL Query Text >> Press Ctrl+C
  6. 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 (899d46d, 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

@mjbvz
Copy link
Contributor

mjbvz commented Jan 21, 2022

Please put together a minimal example that doesn't rely on an complex extension or connecting to a database

You can build on the webview sample for this: https://github.com/microsoft/vscode-extension-samples/tree/main/webview-sample

@mjbvz mjbvz added webview Webview issues info-needed Issue requires more information from poster labels Jan 21, 2022
@soumasar010322
Copy link
Author

@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:

<img src="${catGifPath}" width="300" />
<h1 id="lines-of-code-counter">0</h1>
<script nonce="${nonce}" src="${scriptUri}"></script>

Replaced with

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

image

After making the change, we tried to copy the text using context menu from the Webview but text is not getting copied.

@soumasar010322
Copy link
Author

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.

@connor4312
Copy link
Member

Logan and I ran into this in the hex editor today as well.

@osobeso
Copy link

osobeso commented Mar 4, 2022

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!

@pomdtr
Copy link

pomdtr commented Apr 25, 2022

I have the exact inverse problem in my extension on MacOS (right click copy is working fine, but cmd+c does not work)

@palaashatri
Copy link

@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:
image

@ZeWaka
Copy link

ZeWaka commented Sep 20, 2022

Bumping this issue, it's a bit annoying for users when interfacing with a GUI-based extension.

@CTimmerman
Copy link

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.

https://stackoverflow.com/a/73247563/819417 should fix that and also the copy issue for your extension.

@Fortinbra
Copy link

My team is running into this same issue with the Thunder Client extension, as well as the extensions market place. We cannot cut/copy/paste from these.

@evil-pechenka
Copy link

evil-pechenka commented Jun 6, 2023

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:

  • I copy using the context menu.
  • I paste, but nothing is copied.
  • I copy using the keyboard shortcut.
  • I paste, and everything is copied.

Please watch the video.

243106855-21c79ed2-a064-40ea-92eb-8cdd709ac19a.mp4

@saritbha
Copy link

I'm using a codegpt extension and im not able to copy. what's the point of codegpt then lol

@connor4312
Copy link
Member

Should we remove the "copy" context menu action until it's working? It's rather misleading at the moment.

@StenGruener
Copy link

+1 here on being not able to copy logs from kubernetes addon

@jwoodard80
Copy link

I am having the issue as well in Thunderclient and markdown extensions.

Thank you for any work put forward to resolve this.

@yiliang114
Copy link
Contributor

ref: #205624, Copy Image command in webview is not working neither.

@yiliang114
Copy link
Contributor

@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.
image

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

@yiliang114
Copy link
Contributor

@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.我找到了问题的原因。当我们右键单击webview时,出现的右键菜单实际上是由vscode (而不是webview) 提供的,webview错误地将这种情况视为失去焦点。执行copy命令的回调函数时,无法获取activeWebview值,因此不进行任何操作。

When the right-click menu appears, onBlur is executed.出现右键单击菜单时,将执行onBlur。 image

The error caused vscode to think that there was no webview in the active state at this time.该错误导致vscode认为此时没有处于活动状态的webview。

https://github.com/microsoft/vscode/blob/00abefa3e27ee1866cf6a6ac825578c1ddafd32c/src/vs/workbench/contrib/webview/browser/webview.contribution.ts#L22~L38

I tried to fix the problem in #206529 : only need to judge whether the right-click menu currently appears when judging whether the webview is focused.

@VSCodeTriageBot VSCodeTriageBot added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Mar 11, 2024
@rzhao271 rzhao271 modified the milestones: On Deck, March 2024 Mar 25, 2024
@alexr00 alexr00 added the verified Verification succeeded label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders verified Verification succeeded webview Webview issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.