Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Copy" button to file view of raw text #21629

Merged
merged 16 commits into from
Nov 4, 2022
Merged
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ edit = Edit

copy = Copy
copy_url = Copy URL
copy_content = Copy content
copy_branch = Copy branch name
copy_success = Copied!
copy_error = Copy failed
Expand Down
7 changes: 7 additions & 0 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
<a class="ui mini basic button unescape-button" style="display: none;">{{.locale.Tr "repo.unescape_control_characters"}}</a>
<a class="ui mini basic button escape-button">{{.locale.Tr "repo.escape_control_characters"}}</a>
{{end}}
<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"}}"
{{if or (.IsMarkup) (.IsRenderedHTML) (not .IsTextSource)}}
disabled
{{end}}
>
{{svg "octicon-copy" 14}}
</button>
</div>
<a download href="{{$.RawFileLink}}"><span class="btn-octicon tooltip" data-content="{{.locale.Tr "repo.download_file"}}" data-position="bottom center">{{svg "octicon-download"}}</span></a>
{{if .Repository.CanEnableEditor}}
Expand Down
6 changes: 6 additions & 0 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ export function initGlobalButtons() {
window.location.href = $this.attr('data-done-url');
});
});

// get raw text for copy content button
const text = Array.from(document.querySelectorAll('.lines-code')).map((el) => el.textContent).join('');
for (const copyContentButton of document.querySelectorAll('button.copy-content')) {
copyContentButton.setAttribute('data-clipboard-text', text);
}
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down