diff --git a/modules/base/template.go b/modules/base/template.go index 01ff9f76d..9af2d2cef 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -245,8 +245,17 @@ func DiffLineTypeToStr(diffType int) string { return "same" } -func DiffLinePosToStr(file int, section int, line int) string { - return fmt.Sprintf("%vL%v%v", file + 1, section, line) +func DiffLinePosToStr(filepath string, leftIdx, rightIdx int) string { + var idx int; + var letter string; + if leftIdx > 0 { + idx = leftIdx + letter = "L" + } else { + idx = rightIdx + letter = "R" + } + return fmt.Sprintf("%v%v%v", Sha1(filepath), letter, idx) } func Oauth2Icon(t int) string { diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index adc2bfc55..45a1422bd 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -262,8 +262,10 @@ var Gogs = {}; if ($(this).prop("tagName") == "BUTTON") { lineNum = $(this).attr('rel'); } else { - lineNum = $(this).parent().prev().find('span').attr('rel'); + var span = $(this).parents('tr').find('span:not([rel=""])'); + lineNum = span.first().attr('rel'); } + console.log(lineNum); $('button[rel='+lineNum+']').fadeOut(); lineNum = lineNum.substr(5); var commentTr = $(".comment-"+lineNum); @@ -372,12 +374,9 @@ var Gogs = {}; } }); - $('.code-diff .add-code .lines-code > pre, \ - .code-diff .del-code .lines-code > pre, \ - .code-diff .add-code .lines-code > b, \ - .code-diff .del-code .lines-code > b, \ - .code-diff .add-code .lines-num, \ - .code-diff .del-code .lines-num').hover(function () { + $('.code-diff .lines-code > pre, \ + .code-diff .lines-code > b, \ + .code-diff .lines-num').hover(function () { var $b = $(this).parents('tr').find('b'); $b.addClass('ishovered'); }); diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 73ff2b0c5..887fecd8e 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -394,7 +394,7 @@ func CreateCommitComment(ctx *middleware.Context) { switch ctx.Params(":action") { case "new": line := ctx.Query("line") - lineRe, err := regexp.Compile("[0-9]+L[0-9]+") + lineRe, err := regexp.Compile("[a-zA-Z0-9]{40}[LR][0-9]+") if len(line) > 0 && !lineRe.MatchString(line) { err := errors.New("Something went wrong") send(200, err.Error(), err) diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index de06be080..f02765b37 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -107,7 +107,6 @@ {{range .Sections}} {{range $k, $line := .Lines}} - {{$lineNum := (DiffLinePosToStr $file.Name $line.LeftIdx)}} {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} @@ -120,7 +119,8 @@
{{$line.Content}}
- {{if index $.Comments $lineNum}} + {{$lineNum := (DiffLinePosToStr $file.Name $line.LeftIdx $line.RightIdx)}} + {{if index $.Comments $lineNum }} {{range (index $.Comments $lineNum)}} @@ -162,6 +162,7 @@ {{end}} {{end}} + {{end}} {{end}}