diff options
author | 无闻 <u@gogs.io> | 2015-02-19 19:33:25 -0500 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2015-02-19 19:33:25 -0500 |
commit | 8f1d2d9f240b0ef62df13b8c90d199fcf6069b34 (patch) | |
tree | 1f2e7e53e2c88ac22cc0ed6d3080ca7a76ce715c | |
parent | 77ac1e6ff64a3be94f79190635450f8ba4a41dd2 (diff) | |
parent | 3efe3f42e80a2fd5dfff639be120b2bc5cf28474 (diff) | |
download | gitea-8f1d2d9f240b0ef62df13b8c90d199fcf6069b34.tar.gz gitea-8f1d2d9f240b0ef62df13b8c90d199fcf6069b34.zip |
Merge pull request #972 from makhov/the-new-new-highlighting
fix typo mistake in highlighting
-rw-r--r-- | public/ng/js/gogs.js | 33 | ||||
-rw-r--r-- | templates/repo/diff.tmpl | 2 |
2 files changed, 18 insertions, 17 deletions
diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index bd320b4403..c5fd719c32 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -209,27 +209,28 @@ var Gogs = {}; $list.parents('tr').removeClass('end-selected-line'); $list.parents('tr').find('td').removeClass('selected-line'); if ($from) { - var expr = new RegExp(/diff-(\w+)([LR])(\d+)/); + var expr = new RegExp(/diff-(\w+)([LR]\d+)/); var selectMatches = $select.attr('rel').match(expr) var fromMatches = $from.attr('rel').match(expr) - var a = parseInt(selectMatches[3]); - var b = parseInt(fromMatches[3]); - var linesIntToStr = {}; - linesIntToStr[a] = selectMatches[3]; - linesIntToStr[b] = fromMatches[3]; - - var c; - if (a != b) { - if (a > b) { - c = a; - a = b; - b = c; + var selectTop = $select.offset().top; + var fromTop = $from.offset().top; + var hash; + + if (selectMatches[2] != fromMatches[2]) { + if ((selectTop > fromTop)) { + $startElem = $from; + $endElem = $select; + hash = fromMatches[1]+fromMatches[2] + '-' + selectMatches[2]; + } else { + $startElem = $select; + $endElem = $from; + hash = selectMatches[1]+selectMatches[2] + '-' + fromMatches[2]; } - $('[rel=diff-'+fromMatches[1] + fromMatches[2] + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line'); - var $selectedLines = $('[rel=diff-'+fromMatches[1]+selectMatches[2] + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf(); + $endElem.parents('tr').next().addClass('end-selected-line'); + var $selectedLines = $startElem.parents('tr').nextUntil('.end-selected-line').andSelf(); $selectedLines.find('td.lines-num > span').addClass('active') $selectedLines.find('td').addClass('selected-line'); - $.changeHash('#diff-'+fromMatches[1]+fromMatches[2] + linesIntToStr[a] + '-' + selectMatches[2] + + linesIntToStr[b]); + $.changeHash('#diff-'+hash); return } } diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 7da932a4f8..f261da55a0 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -109,7 +109,7 @@ {{range $k, $line := .Lines}} <tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$k}} ol-{{$k}}"> <td class="lines-num lines-num-old"> - <span rel="{{if $line.LeftIdx}}diff-L{{Sha1 $file.Name}}{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span> + <span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span> </td> <td class="lines-num lines-num-new"> <span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span> |