diff --git a/extensions/markdown-language-features/preview-src/index.ts b/extensions/markdown-language-features/preview-src/index.ts index 380223ccdaf..6c70e58ee7e 100644 --- a/extensions/markdown-language-features/preview-src/index.ts +++ b/extensions/markdown-language-features/preview-src/index.ts @@ -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(); } }