diff --git a/models/issue_comment.go b/models/issue_comment.go index 9b5b3ed45b7a..79311c5aa1a0 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 78fc202a9b33..42342c2147af 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++) { $('