Skip to content

Commit 5b584a9

Browse files
committed
fix
1 parent 83a41f0 commit 5b584a9

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

templates/repo/view_file.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<a class="ui mini basic button unescape-button" style="display: none;">{{.locale.Tr "repo.unescape_control_characters"}}</a>
5959
<a class="ui mini basic button escape-button">{{.locale.Tr "repo.escape_control_characters"}}</a>
6060
{{end}}
61-
<button class="ui mini basic button small compact tooltip copy-content" id="clipboard-btn" data-content="{{.locale.Tr "copy_content"}}" aria-label="{{.locale.Tr "copy_content"}}"
61+
<button class="ui mini basic button small compact tooltip" id="copy-file-content" data-content="{{.locale.Tr "copy_content"}}" aria-label="{{.locale.Tr "copy_content"}}"
6262
{{if or (.IsMarkup) (.IsRenderedHTML) (not .IsTextSource)}}
6363
disabled
6464
{{end}}

web_src/js/features/common-global.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,6 @@ export function initGlobalButtons() {
343343
window.location.href = $this.attr('data-done-url');
344344
});
345345
});
346-
347-
// get raw text for copy content button
348-
const copyContentButtons = document.querySelectorAll('button.copy-content');
349-
if (copyContentButtons.length !== 0) {
350-
const text = Array.from(document.querySelectorAll('.lines-code')).map((el) => el.textContent).join('');
351-
for (const copyContentButton of copyContentButtons) {
352-
copyContentButton.setAttribute('data-clipboard-text', text);
353-
}
354-
}
355346
}
356347

357348
/**

web_src/js/features/repo-code.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import $ from 'jquery';
22
import {svg} from '../svg.js';
33
import {invertFileFolding} from './file-fold.js';
4-
import {createTippy} from '../modules/tippy.js';
4+
import {createTippy, showTemporaryTooltip} from '../modules/tippy.js';
55
import {copyToClipboard} from './clipboard.js';
66

7+
const {i18n} = window.config;
8+
79
function changeHash(hash) {
810
if (window.history.pushState) {
911
window.history.pushState(null, null, hash);
@@ -110,6 +112,18 @@ function showLineButton() {
110112
});
111113
}
112114

115+
function initCopyFileContent() {
116+
// get raw text for copy content button, at the moment, only one button (and one related file content) is supported.
117+
const copyFileContent = document.querySelector('#copy-file-content');
118+
if (!copyFileContent) return;
119+
120+
copyFileContent.addEventListener('click', async () => {
121+
const text = Array.from(document.querySelectorAll('.file-view .lines-code')).map((el) => el.textContent).join('');
122+
const success = await copyToClipboard(text);
123+
showTemporaryTooltip(copyFileContent, success ? i18n.copy_success : i18n.copy_error);
124+
});
125+
}
126+
113127
export function initRepoCodeView() {
114128
if ($('.code-view .lines-num').length > 0) {
115129
$(document).on('click', '.lines-num span', function (e) {
@@ -185,4 +199,5 @@ export function initRepoCodeView() {
185199
if (!success) return;
186200
document.querySelector('.code-line-button')?._tippy?.hide();
187201
});
202+
initCopyFileContent();
188203
}

0 commit comments

Comments
 (0)