-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Cannot paste content copied from outside on VS Code Web #200641
Comments
@mjbvz Seems like we're not properly reading the right contents when pasting in the editor
|
Seems caused by the web clipboard being in-memory:
In the copy paste controller, I explicitly clear it to work around this:
However that won't work for external copies |
This is tough to get right using web APIs where support for custom formats is very limited. Our solution is not very robust and thus leads to this issue. I have played around for 10 minutes writing a different type into the clipboard for the async writeResources(resources: URI[]): Promise<void> {
try {
return await navigator.clipboard.write([
new ClipboardItem({
['text/html']: new Blob([`<vscode>${resourcesToBuffer(resources).toString()}</vscode>`], { type: 'text/html' }),
})
]);
} catch (error) {
console.error(error);
}
// fallback to in-memory
this.resources = resources;
}
async readResources(): Promise<URI[]> {
try {
const clipboardItems = await navigator.clipboard.read();
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
if (type !== 'text/html') {
continue;
}
const blob = await clipboardItem.getType(type);
console.log(await blob.text());
// TODO convert back to URI if matching our format
}
}
} catch (error) {
console.error(error);
}
// fallback to in-memory
return this.resources;
} One immediate issue is that We could maybe encode this into Maybe @deepak1556 for additional thoughts. |
I think this is actually quite a severe issue in web. Once you have resources in your clipboard, it seems to me you cannot paste anything else into the editor but that (!). So for example, these steps are much easier to reproduce:
One approach to solve this (see #200782) is to associate the resources with a state that is specific to the contents of the clipboard at that time with the goal to detect if that state has changed or not. Its ugly, because then vscode/src/vs/platform/clipboard/browser/clipboardService.ts Lines 183 to 195 in 5cf08ac
|
I am also adding code to reset the vscode/src/vs/platform/clipboard/browser/clipboardService.ts Lines 32 to 38 in 33f67c2
I believe that would make the code here obsolete:
|
Thank you for the quick resolution! |
This should work fine now from our insiders build if you want to verify: https://insiders.vscode.dev/ |
It works for me, thanks! |
Was this released into 1.85.1? |
Commit: af28b32
Date: 2023-12-06T18:18:26.691Z (5 days ago)
Steps to Reproduce:
Expected result:
The text copied outside of VS Code should be pasted there.
Current result:
It pastes the path of the file copied by step 2 in the file explorer.
This blocks me from using copy & paste properly until I reload VS Code completely.
The text was updated successfully, but these errors were encountered: