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:
Matt Bierner
2025-03-25 13:35:14 -07:00
committed by GitHub

View File

@@ -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();
}
}