Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}

/**
Expand Down