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
|
@ -1,10 +1,9 @@
|
|||
import $ from 'jquery';
|
||||
import {svg} from '../svg.js';
|
||||
import {invertFileFolding} from './file-fold.js';
|
||||
import {createTippy, showTemporaryTooltip} from '../modules/tippy.js';
|
||||
import {createTippy} from '../modules/tippy.js';
|
||||
import {copyToClipboard} from './clipboard.js';
|
||||
|
||||
const {i18n} = window.config;
|
||||
export const singleAnchorRegex = /^#(L|n)([1-9][0-9]*)$/;
|
||||
export const rangeAnchorRegex = /^#(L[1-9][0-9]*)-(L[1-9][0-9]*)$/;
|
||||
|
||||
|
@ -114,18 +113,6 @@ function showLineButton() {
|
|||
});
|
||||
}
|
||||
|
||||
function initCopyFileContent() {
|
||||
// get raw text for copy content button, at the moment, only one button (and one related file content) is supported.
|
||||
const copyFileContent = document.querySelector('#copy-file-content');
|
||||
if (!copyFileContent) return;
|
||||
|
||||
copyFileContent.addEventListener('click', async () => {
|
||||
const text = Array.from(document.querySelectorAll('.file-view .lines-code')).map((el) => el.textContent).join('');
|
||||
const success = await copyToClipboard(text);
|
||||
showTemporaryTooltip(copyFileContent, success ? i18n.copy_success : i18n.copy_error);
|
||||
});
|
||||
}
|
||||
|
||||
export function initRepoCodeView() {
|
||||
if ($('.code-view .lines-num').length > 0) {
|
||||
$(document).on('click', '.lines-num span', function (e) {
|
||||
|
@ -205,5 +192,4 @@ export function initRepoCodeView() {
|
|||
if (!success) return;
|
||||
document.querySelector('.code-line-button')?._tippy?.hide();
|
||||
});
|
||||
initCopyFileContent();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue