mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 04:23:32 +01:00
Merge pull request #240508 from notoriousmango/copy-image-handle-error
fix: use the copy command for images with CORS errors in the markdown preview
This commit is contained in:
@@ -184,6 +184,17 @@ async function copyImage(image: HTMLImageElement, retries = 5) {
|
||||
})]);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
const selection = window.getSelection();
|
||||
if (!selection) {
|
||||
await navigator.clipboard.writeText(image.getAttribute('data-src') ?? image.src);
|
||||
return;
|
||||
}
|
||||
selection.removeAllRanges();
|
||||
const range = document.createRange();
|
||||
range.selectNode(image);
|
||||
selection.addRange(range);
|
||||
document.execCommand('copy');
|
||||
selection.removeAllRanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user