Skip to content

Commit 03eba32

Browse files
authored
Add a new menu in file view to open blame view and fix blame view select range bug (#19500)
1 parent fef26c1 commit 03eba32

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

options/locale/locale_en-US.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ line_unicode = `This line has hidden unicode characters`
10411041
escape_control_characters = Escape
10421042
unescape_control_characters = Unescape
10431043
file_copy_permalink = Copy Permalink
1044+
view_git_blame = View Git Blame
10441045
video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
10451046
audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
10461047
stored_lfs = Stored with Git LFS
@@ -3088,7 +3089,7 @@ settings.link = Link this package to a repository
30883089
settings.link.description = If you link a package with a repository, the package is listed in the repository's package list.
30893090
settings.link.select = Select Repository
30903091
settings.link.button = Update Repository Link
3091-
settings.link.success = Repository link was successfully updated.
3092+
settings.link.success = Repository link was successfully updated.
30923093
settings.link.error = Failed to update repository link.
30933094
settings.delete = Delete package
30943095
settings.delete.description = Deleting a package is permanent and cannot be undone.

templates/repo/view_file.tmpl

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
<a class="item ref-in-new-issue" href="{{.RepoLink}}/issues/new?body={{.Repository.HTMLURL}}{{printf "/src/commit/" }}{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}" rel="nofollow noindex">{{.i18n.Tr "repo.issues.context.reference_issue"}}</a>
129129
</div>
130130
{{end}}
131+
<div class="ui link list">
132+
<a class="item view_git_blame" href="{{.Repository.HTMLURL}}/blame/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}">{{.i18n.Tr "repo.view_git_blame"}}</a>
133+
</div>
131134
<div class="ui link list">
132135
<a data-clipboard-text="{{.Repository.HTMLURL}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}" class="item copy-line-permalink">{{.i18n.Tr "repo.file_copy_permalink"}}</a>
133136
</div>

web_src/js/features/repo-code.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ function selectRange($list, $select, $from) {
1515
// add hashchange to permalink
1616
const $issue = $('a.ref-in-new-issue');
1717
const $copyPermalink = $('a.copy-line-permalink');
18-
19-
if ($copyPermalink.length === 0) {
20-
return;
21-
}
18+
const $viewGitBlame = $('a.view_git_blame');
2219

2320
const updateIssueHref = function (anchor) {
2421
if ($issue.length === 0) {
@@ -29,7 +26,22 @@ function selectRange($list, $select, $from) {
2926
$issue.attr('href', href);
3027
};
3128

29+
const updateViewGitBlameFragment = function (anchor) {
30+
if ($viewGitBlame.length === 0) {
31+
return;
32+
}
33+
let href = $viewGitBlame.attr('href');
34+
href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`;
35+
if (anchor.length !== 0) {
36+
href = `${href}#${anchor}`;
37+
}
38+
$viewGitBlame.attr('href', href);
39+
};
40+
3241
const updateCopyPermalinkHref = function(anchor) {
42+
if ($copyPermalink.length === 0) {
43+
return;
44+
}
3345
let link = $copyPermalink.attr('data-clipboard-text');
3446
link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`;
3547
$copyPermalink.attr('data-clipboard-text', link);
@@ -53,6 +65,7 @@ function selectRange($list, $select, $from) {
5365
changeHash(`#L${a}-L${b}`);
5466

5567
updateIssueHref(`L${a}-L${b}`);
68+
updateViewGitBlameFragment(`L${a}-L${b}`);
5669
updateCopyPermalinkHref(`L${a}-L${b}`);
5770
return;
5871
}
@@ -61,6 +74,7 @@ function selectRange($list, $select, $from) {
6174
changeHash(`#${$select.attr('rel')}`);
6275

6376
updateIssueHref($select.attr('rel'));
77+
updateViewGitBlameFragment($select.attr('rel'));
6478
updateCopyPermalinkHref($select.attr('rel'));
6579
}
6680

0 commit comments

Comments
 (0)