diff --git a/models/issue_comment.go b/models/issue_comment.go index 9b5b3ed45b..79311c5aa1 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -345,11 +345,7 @@ func (c *Comment) getPathAndFile(repoPath string) (string, string) { func (c *Comment) checkInvalidation(e Engine, repo *git.Repository, branch string) error { p, file := c.getPathAndFile(repo.Path) // FIXME differentiate between previous and proposed line - var line = c.Line - if line < 0 { - line *= -1 - } - commit, err := repo.LineBlame(branch, p, file, uint(line)) + commit, err := repo.LineBlame(branch, p, file, uint(c.UnsignedLine())) if err != nil { return err } @@ -366,6 +362,22 @@ func (c *Comment) CheckInvalidation(repo *git.Repository, branch string) error { return c.checkInvalidation(x, repo, branch) } +// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes. +func (c *Comment) DiffSide() string { + if c.Line < 0 { + return "previous" + } + return "proposed" +} + +// UnsignedLine returns the LOC of the code comment without + or - +func (c *Comment) UnsignedLine() uint64 { + if c.Line < 0 { + return uint64(c.Line * -1) + } + return uint64(c.Line) +} + func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) { var LabelID int64 if opts.Label != nil { diff --git a/public/js/index.js b/public/js/index.js index 78fc202a9b..42342c2147 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -789,6 +789,7 @@ function initPullRequestReview() { var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split'); var side = $(this).data('side'); var idx = $(this).data('idx'); + var path = $(this).data('path'); var form = $('#pull_review_add_comment').html(); var tr = $(this).closest('tr'); var ntr = tr.next(); @@ -815,12 +816,12 @@ function initPullRequestReview() { commentCloud.find('.tab.segment').each(function(i, item) { $(item).attr('data-tab', $(item).attr('data-tab') + id); }); + td.find("input[name='line']").val(idx); + td.find("input[name='side']").val(side === "left" ? "previous":"proposed"); + td.find("input[name='path']").val(path); initCommentPreviewTab(commentCloud.find('.form')); } commentCloud.find('textarea').focus(); - - - //alert($(this).data('side') + $(this).data('idx')); }); } @@ -2265,7 +2266,7 @@ function initTopicbar() { return } var topicArray = topics.split(","); - + var last = viewDiv.children("a").last(); for (var i=0;i < topicArray.length; i++) { $('
'+topicArray[i]+'
').insertBefore(last) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 113980e960..2e006b121b 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -102,7 +102,7 @@ {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} {{if $line.LeftIdx}} - + + + {{end}} @@ -111,7 +111,7 @@ {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} {{if $line.RightIdx}} - + + + {{end}} @@ -128,7 +128,7 @@ {{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}} - {{template "repo/diff/comment_form" $}} + {{template "repo/diff/comment_form_datahandler" dict "root" $ "comment" (index $line.Comments 0)}} @@ -158,7 +158,7 @@ {{end}}
- {{template "repo/diff/new_comment" .}} + {{template "repo/diff/new_comment" dict "root" .}}
{{if .IsSplitStyle}} diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index a27494ab42..4e6d44220a 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -1,37 +1,36 @@ -
-{{.CsrfTokenHtml}} - - - - + +{{$.root.CsrfTokenHtml}} + + +
- +
{{.i18n.Tr "loading"}}
diff --git a/templates/repo/diff/comment_form_datahandler.tmpl b/templates/repo/diff/comment_form_datahandler.tmpl new file mode 100644 index 0000000000..be18dfdb6d --- /dev/null +++ b/templates/repo/diff/comment_form_datahandler.tmpl @@ -0,0 +1,7 @@ +{{if $.comment}} + {{ template "repo/diff/comment_form" dict "root" $.root "Line" $.comment.UnsignedLine "File" $.comment.TreePath "Side" $.comment.DiffSide}} +{{else if $.root}} + {{ template "repo/diff/comment_form" $}} +{{else}} + {{ template "repo/diff/comment_form" dict "root" $}} +{{end}} diff --git a/templates/repo/diff/new_comment.tmpl b/templates/repo/diff/new_comment.tmpl index 12779c0e6f..d8b6ccb9dd 100644 --- a/templates/repo/diff/new_comment.tmpl +++ b/templates/repo/diff/new_comment.tmpl @@ -1,3 +1,3 @@
- {{ template "repo/diff/comment_form" .}} + {{template "repo/diff/comment_form_datahandler" .}}
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index 74174f1a11..9e163b6d40 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -13,7 +13,7 @@ {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} - + + + {{end}} @@ -29,7 +29,7 @@ {{ template "repo/diff/comments" dict "root" $.root "comments" $line.Comments}} - {{template "repo/diff/comment_form" $.root }} + {{template "repo/diff/comment_form_datahandler" dict "root" $.root "comment" (index $line.Comments 0)}}