Skip to content

Commit eb0359c

Browse files
jolheiserlafriks
authored andcommitted
Context menus for comments (#9043)
* Add quote replies Signed-off-by: jolheiser <[email protected]>
1 parent af7f08b commit eb0359c

File tree

10 files changed

+110
-63
lines changed

10 files changed

+110
-63
lines changed

options/locale/locale_en-US.ini

+4
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ issues.closed_title = Closed
867867
issues.num_comments = %d comments
868868
issues.commented_at = `commented <a href="#%s">%s</a>`
869869
issues.delete_comment_confirm = Are you sure you want to delete this comment?
870+
issues.context.copy_link = Copy Link
871+
issues.context.quote_reply = Quote Reply
872+
issues.context.edit = Edit
873+
issues.context.delete = Delete
870874
issues.no_content = There is no content yet.
871875
issues.close_issue = Close
872876
issues.close_comment_issue = Comment and Close

public/css/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ i.icon.centerlock{top:1.5em}
573573
.repository.view.issue .comment-list .comment .tag{color:#767676;margin-top:3px;padding:2px 5px;font-size:12px;border:1px solid rgba(0,0,0,.1);border-radius:3px}
574574
.repository.view.issue .comment-list .comment .tag.pending{color:#000;background-color:#fffbb2;margin-left:5px}
575575
.repository.view.issue .comment-list .comment .actions .item{float:left}
576+
.repository.view.issue .comment-list .comment .actions .item.context{float:none}
576577
.repository.view.issue .comment-list .comment .actions .item.tag{margin-right:5px}
577578
.repository.view.issue .comment-list .comment .actions .item.action{margin-top:6px;margin-left:10px}
578579
.repository.view.issue .comment-list .comment .content{margin-left:4em}

public/js/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/repo/diff/comments.tmpl

+2-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
{{end}}
2222
{{end}}
2323
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) }}
24-
{{if or $.root.Permission.IsAdmin (eq .Poster.ID $.root.SignedUserID)}}
25-
<div class="item action">
26-
<a class="edit-content" href="#"><i class="octicon octicon-pencil"></i></a>
27-
<a class="delete-comment" href="#" data-comment-id={{.HashTag}} data-url="{{$.root.RepoLink}}/comments/{{.ID}}/delete" data-locale="{{$.root.i18n.Tr "repo.issues.delete_comment_confirm"}}"><i class="octicon octicon-x"></i></a>
28-
</div>
29-
{{end}}
24+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $.root "item" . "delete" true "diff" true }}
3025
</div>
3126
</div>
3227
<div class="ui attached segment">
@@ -37,7 +32,7 @@
3732
<span class="no-content">{{$.root.i18n.Tr "repo.issues.no_content"}}</span>
3833
{{end}}
3934
</div>
40-
<div class="raw-content hide">{{.Content}}</div>
35+
<div id="comment-{{.ID}}" class="raw-content hide">{{.Content}}</div>
4136
<div class="edit-content-zone hide" data-write="issuecomment-{{.ID}}-write" data-preview="issuecomment-{{.ID}}-preview" data-update-url="{{$.root.RepoLink}}/comments/{{.ID}}" data-context="{{$.root.RepoLink}}"></div>
4237
</div>
4338
{{$reactions := .Reactions.GroupByType}}

templates/repo/issue/view_content.tmpl

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
{{if not $.Repository.IsArchived}}
3030
<div class="ui right actions">
3131
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) }}
32-
{{if or .IsIssueWriter .IsIssuePoster}}
33-
<div class="item action">
34-
<a class="edit-content" href="#"><i class="octicon octicon-pencil"></i></a>
35-
</div>
36-
{{end}}
32+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "diff" false }}
3733
</div>
3834
{{end}}
3935
</div>
@@ -45,7 +41,7 @@
4541
<span class="no-content">{{.i18n.Tr "repo.issues.no_content"}}</span>
4642
{{end}}
4743
</div>
48-
<div class="raw-content hide">{{.Issue.Content}}</div>
44+
<div id="comment-{{.Issue.ID}}" class="raw-content hide">{{.Issue.Content}}</div>
4945
<div class="edit-content-zone hide" data-write="issue-{{.Issue.ID}}-write" data-preview="issue-{{.Issue.ID}}-preview" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/content" data-context="{{.RepoLink}}" data-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/attachments" data-view-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/view-attachments"></div>
5046
</div>
5147
{{$reactions := .Issue.Reactions.GroupByType}}

templates/repo/issue/view_content/comments.tmpl

+38-43
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,23 @@
2323
{{else}}
2424
<span class="text grey"><a {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>{{.Poster.GetDisplayName}}</a> {{$.i18n.Tr "repo.issues.commented_at" .HashTag $createdStr | Safe}}</span>
2525
{{end}}
26-
{{if not $.Repository.IsArchived}}
27-
<div class="ui right actions">
28-
{{if gt .ShowTag 0}}
29-
<div class="item tag">
30-
{{if eq .ShowTag 1}}
31-
{{$.i18n.Tr "repo.issues.poster"}}
32-
{{else if eq .ShowTag 2}}
33-
{{$.i18n.Tr "repo.issues.collaborator"}}
34-
{{else if eq .ShowTag 3}}
35-
{{$.i18n.Tr "repo.issues.owner"}}
36-
{{end}}
37-
</div>
38-
{{end}}
39-
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) }}
40-
{{if or $.Permission.IsAdmin (eq .Poster.ID $.SignedUserID)}}
41-
<div class="item action">
42-
<a class="edit-content" href="#"><i class="octicon octicon-pencil"></i></a>
43-
<a class="delete-comment" href="#" data-comment-id={{.HashTag}} data-url="{{$.RepoLink}}/comments/{{.ID}}/delete" data-locale="{{$.i18n.Tr "repo.issues.delete_comment_confirm"}}"><i class="octicon octicon-x"></i></a>
44-
</div>
45-
{{end}}
46-
</div>
47-
{{end}}
26+
{{if not $.Repository.IsArchived}}
27+
<div class="ui right actions">
28+
{{if gt .ShowTag 0}}
29+
<div class="item tag">
30+
{{if eq .ShowTag 1}}
31+
{{$.i18n.Tr "repo.issues.poster"}}
32+
{{else if eq .ShowTag 2}}
33+
{{$.i18n.Tr "repo.issues.collaborator"}}
34+
{{else if eq .ShowTag 3}}
35+
{{$.i18n.Tr "repo.issues.owner"}}
36+
{{end}}
37+
</div>
38+
{{end}}
39+
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) }}
40+
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "diff" false }}
41+
</div>
42+
{{end}}
4843
</div>
4944
<div class="ui attached segment">
5045
<div class="render-content markdown has-emoji">
@@ -54,7 +49,7 @@
5449
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
5550
{{end}}
5651
</div>
57-
<div class="raw-content hide">{{.Content}}</div>
52+
<div id="comment-{{.ID}}" class="raw-content hide">{{.Content}}</div>
5853
<div class="edit-content-zone hide" data-write="issuecomment-{{.ID}}-write" data-preview="issuecomment-{{.ID}}-preview" data-update-url="{{$.RepoLink}}/comments/{{.ID}}" data-context="{{$.RepoLink}}" data-attachment-url="{{$.RepoLink}}/comments/{{.ID}}/attachments"></div>
5954
</div>
6055
{{$reactions := .Reactions.GroupByType}}
@@ -277,29 +272,29 @@
277272
<span class="octicon octicon-primitive-dot"></span>
278273
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
279274
<img src="{{.Poster.RelAvatarLink}}">
280-
</a>
281-
<span class="text grey">
282-
{{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink (.Poster.GetDisplayName|Escape) $createdStr | Safe}}
283-
</span>
284-
<div class="detail">
275+
</a>
276+
<span class="text grey">
277+
{{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink (.Poster.GetDisplayName|Escape) $createdStr | Safe}}
278+
</span>
279+
<div class="detail">
285280
<span class="octicon octicon-plus"></span>
286-
<span class="text grey"><a href="{{$.RepoLink}}/issues/{{.DependentIssue.Index}}">#{{.DependentIssue.Index}} {{.DependentIssue.Title}}</a></span>
287-
</div>
288-
</div>
281+
<span class="text grey"><a href="{{$.RepoLink}}/issues/{{.DependentIssue.Index}}">#{{.DependentIssue.Index}} {{.DependentIssue.Title}}</a></span>
282+
</div>
283+
</div>
289284
{{else if eq .Type 20}}
290285
<div class="event" id="{{.HashTag}}">
291-
<span class="octicon octicon-primitive-dot"></span>
292-
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
293-
<img src="{{.Poster.RelAvatarLink}}">
294-
</a>
295-
<span class="text grey">
296-
{{$.i18n.Tr "repo.issues.dependency.removed_dependency" .Poster.HomeLink (.Poster.GetDisplayName|Escape) $createdStr | Safe}}
297-
</span>
298-
<div class="detail">
299-
<span class="text grey octicon octicon-trashcan"></span>
300-
<span class="text grey"><a href="{{$.RepoLink}}/issues/{{.DependentIssue.Index}}">#{{.DependentIssue.Index}} {{.DependentIssue.Title}}</a></span>
301-
</div>
302-
</div>
286+
<span class="octicon octicon-primitive-dot"></span>
287+
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
288+
<img src="{{.Poster.RelAvatarLink}}">
289+
</a>
290+
<span class="text grey">
291+
{{$.i18n.Tr "repo.issues.dependency.removed_dependency" .Poster.HomeLink (.Poster.GetDisplayName|Escape) $createdStr | Safe}}
292+
</span>
293+
<div class="detail">
294+
<span class="text grey octicon octicon-trashcan"></span>
295+
<span class="text grey"><a href="{{$.RepoLink}}/issues/{{.DependentIssue.Index}}">#{{.DependentIssue.Index}} {{.DependentIssue.Title}}</a></span>
296+
</div>
297+
</div>
303298
{{else if eq .Type 22}}
304299
<div class="event" id="{{.HashTag}}">
305300
<span class="octicon octicon-{{.Review.Type.Icon}} issue-symbol"></span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{if .ctx.IsSigned}}
2+
<div class="item action ui pointing top right custom dropdown context-dropdown">
3+
<a class="context-menu">
4+
<i class="fa fa-ellipsis-h"></i>
5+
</a>
6+
<div class="menu">
7+
{{if .diff}}
8+
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
9+
{{else}}
10+
<div class="item context clipboard" data-clipboard-text="{{Printf "%s%s/issues/%d#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
11+
{{end}}
12+
<div class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.ID}}">{{.ctx.i18n.Tr "repo.issues.context.quote_reply"}}</div>
13+
{{if or .ctx.Permission.IsAdmin (eq .item.Poster.ID .ctx.SignedUserID)}}
14+
<div class="divider"></div>
15+
<div class="item context edit-content">{{.ctx.i18n.Tr "repo.issues.context.edit"}}</div>
16+
{{if .delete}}
17+
<div class="item context delete-comment" data-comment-id={{.item.HashTag}} data-url="{{.ctx.RepoLink}}/comments/{{.item.ID}}/delete" data-locale="{{.ctx.i18n.Tr "repo.issues.delete_comment_confirm"}}">{{.ctx.i18n.Tr "repo.issues.context.delete"}}</div>
18+
{{end}}
19+
{{end}}
20+
</div>
21+
</div>
22+
{{end}}

web_src/js/index.js

+35-5
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,41 @@ function initRepository() {
732732
return false;
733733
});
734734

735+
// Issue/PR Context Menus
736+
$('.context-dropdown').dropdown({
737+
action: 'hide'
738+
});
739+
740+
// Quote reply
741+
$('.quote-reply').click(function (event) {
742+
$(this).closest('.dropdown').find('.menu').toggle('visible');
743+
const target = $(this).data('target');
744+
745+
let $content;
746+
if ($(this).hasClass('quote-reply-diff')) {
747+
const $parent = $(this).closest('.comment-code-cloud');
748+
$parent.find('button.comment-form-reply').click();
749+
$content = $parent.find('[name="content"]');
750+
} else {
751+
$content = $('#content');
752+
}
753+
754+
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
755+
const content = `> ${quote}\n\n`;
756+
757+
if ($content.val() !== '') {
758+
$content.val(`${$content.val()}\n\n${content}`);
759+
} else {
760+
$content.val(`${content}`);
761+
}
762+
$content.focus();
763+
event.preventDefault();
764+
});
765+
735766
// Edit issue or comment content
736-
$('.edit-content').click(function () {
737-
const $segment = $(this).parent().parent().parent()
738-
.next();
767+
$('.edit-content').click(function (event) {
768+
$(this).closest('.dropdown').find('.menu').toggle('visible');
769+
const $segment = $(this).closest('.header').next();
739770
const $editContentZone = $segment.find('.edit-content-zone');
740771
const $renderContent = $segment.find('.render-content');
741772
const $rawContent = $segment.find('.raw-content');
@@ -881,7 +912,7 @@ function initRepository() {
881912
$textarea.val($rawContent.text());
882913
}
883914
$textarea.focus();
884-
return false;
915+
event.preventDefault();
885916
});
886917

887918
// Delete comment
@@ -931,7 +962,6 @@ function initRepository() {
931962
$(this).closest('.form').hide();
932963
$mergeButton.parent().show();
933964
});
934-
935965
initReactionSelector();
936966
}
937967

web_src/less/_repository.less

+4
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@
748748
.item {
749749
float: left;
750750

751+
&.context {
752+
float: none;
753+
}
754+
751755
&.tag {
752756
margin-right: 5px;
753757
}

0 commit comments

Comments
 (0)