Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -969,6 +969,7 @@ file_view_rendered = View Rendered
file_view_raw = View Raw
file_permalink = Permalink
file_too_large = The file is too large to be shown.
file_copy_permalink = Copy Permalink
video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
stored_lfs = Stored with Git LFS
Expand Down
23 changes: 15 additions & 8 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,20 @@
{{end}}
</tbody>
</table>
{{if $.Permission.CanRead $.UnitTypeIssues}}
<div class="code-line-menu ui fluid popup transition hidden">
<div class="ui column relaxed equal height">
<div class="column">
<div class="ui link list">
<a class="item ref-in-new-issue" href="{{.RepoLink}}/issues/new?body={{URLJoin AppUrl .RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.issues.context.reference_issue"}}</a>
</div>
<div class="code-line-menu ui fluid popup transition hidden">
<div class="ui column relaxed equal height">
<div class="column">
{{if $.Permission.CanRead $.UnitTypeIssues}}
<div class="ui link list">
<a class="item ref-in-new-issue" href="{{.RepoLink}}/issues/new?body={{URLJoin AppUrl .RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.issues.context.reference_issue"}}</a>
</div>
{{end}}
<div class="ui link list">
<a class="item copy-line-permalink" href="{{URLJoin AppUrl .RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}" onClick="return copy(this);">{{.i18n.Tr "repo.file_copy_permalink"}}</a>
</div>
</div>
{{end}}
</div>
</div>
{{end}}
{{end}}
</div>
Expand All @@ -137,4 +140,8 @@ function submitDeleteForm() {
$("#delete-file-form").submit()
}
}
function copy(link) {
navigator.clipboard.writeText(link.href);
return false;
}
</script>
20 changes: 18 additions & 2 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2927,8 +2927,9 @@ function selectRange($list, $select, $from) {

// add hashchange to permalink
const $issue = $('a.ref-in-new-issue');
const $copyPermalink = $('a.copy-line-permalink');

if ($issue.length === 0) {
if ($issue.length === 0 || $copyPermalink.length === 0) {
return;
}

Expand All @@ -2938,6 +2939,13 @@ function selectRange($list, $select, $from) {
} else {
$issue.attr('href', `${$issue.attr('href')}%23L${a}-L${b}`);
}

const matchedPermalink = $copyPermalink.attr('href').match(/#L\d+$|#L\d+-L\d+$/);
if (matchedPermalink) {
$copyPermalink.attr('href', $copyPermalink.attr('href').replace($copyPermalink.attr('href').substr(matchedPermalink.index), `#L${a}-L${b}`));
} else {
$copyPermalink.attr('href', `${$copyPermalink.attr('href')}#L${a}-L${b}`);
}
return;
}
}
Expand All @@ -2946,8 +2954,9 @@ function selectRange($list, $select, $from) {

// add hashchange to permalink
const $issue = $('a.ref-in-new-issue');
const $copyPermalink = $('a.copy-line-permalink');

if ($issue.length === 0) {
if ($issue.length === 0 || $copyPermalink.length === 0) {
return;
}

Expand All @@ -2957,6 +2966,13 @@ function selectRange($list, $select, $from) {
} else {
$issue.attr('href', `${$issue.attr('href')}%23${$select.attr('rel')}`);
}

const matchedPermalink = $copyPermalink.attr('href').match(/#L\d+$|#L\d+-L\d+$/);
if (matchedPermalink) {
$copyPermalink.attr('href', $copyPermalink.attr('href').replace($copyPermalink.attr('href').substr(matchedPermalink.index), `#${$select.attr('rel')}`));
} else {
$copyPermalink.attr('href', `${$copyPermalink.attr('href')}#${$select.attr('rel')}`);
}
}

$(() => {
Expand Down