Improvements for Content Copy (#21842)
It now supports copying Markdown, SVG and Images (not in Firefox currently because of lacking [`ClipboardItem`](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem) support, but can be enabled in `about:config` and works). It will fetch the data if in a rendered view or when it's an image. Followup to https://github.com/go-gitea/gitea/pull/21629.
This commit is contained in:
parent
e4eaa68a2b
commit
c2fb27beb4
12 changed files with 144 additions and 29 deletions
|
@ -2,11 +2,16 @@ import {showTemporaryTooltip} from '../modules/tippy.js';
|
|||
|
||||
const {copy_success, copy_error} = window.config.i18n;
|
||||
|
||||
export async function copyToClipboard(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
return fallbackCopyToClipboard(text);
|
||||
export async function copyToClipboard(content) {
|
||||
if (content instanceof Blob) {
|
||||
const item = new window.ClipboardItem({[content.type]: content});
|
||||
await navigator.clipboard.write([item]);
|
||||
} else { // text
|
||||
try {
|
||||
await navigator.clipboard.writeText(content);
|
||||
} catch {
|
||||
return fallbackCopyToClipboard(content);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue