Browse Source

new lines highlighting format

tags/v1.2.0-rc1
Alexey Makhov 10 years ago
parent
commit
911e54ba09
1 changed files with 20 additions and 14 deletions
  1. +20
    -14
      public/ng/js/gogs.js

+ 20
- 14
public/ng/js/gogs.js View File

@@ -206,10 +206,18 @@ var Gogs = {};
Gogs.renderDiffView = function () { Gogs.renderDiffView = function () {
function selectRange($list, $select, $from) { function selectRange($list, $select, $from) {
$list.removeClass('active'); $list.removeClass('active');
$list.parents('tr').removeClass('end-selected-line');
$list.parents('tr').find('td').removeClass('selected-line'); $list.parents('tr').find('td').removeClass('selected-line');
if ($from) { if ($from) {
var a = parseInt($select.attr('rel').substr(1));
var b = parseInt($from.attr('rel').substr(1));
var expr = new RegExp(/diff-(\d+)L(\d+)/);
var selectMatches = $select.attr('rel').match(expr)
var fromMatches = $from.attr('rel').match(expr)
var a = parseInt(selectMatches[2]);
var b = parseInt(fromMatches[2]);
var linesIntToStr = {};
linesIntToStr[a] = selectMatches[2];
linesIntToStr[b] = fromMatches[2];

var c; var c;
if (a != b) { if (a != b) {
if (a > b) { if (a > b) {
@@ -217,13 +225,11 @@ var Gogs = {};
a = b; a = b;
b = c; b = c;
} }
var classes = [];
for (i = a; i <= b; i++) {
classes.push('[rel=L' + i + ']');
}
$list.filter(classes.join(',')).addClass('active');
$list.filter(classes.join(',')).parents('tr').find('td').addClass('selected-line');
$.changeHash('#L' + a + '-' + 'L' + b);
$('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line');
var $selectedLines = $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[a] + ']').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]+'L' + linesIntToStr[a] + '-L' + linesIntToStr[b]);
return return
} }
} }
@@ -256,18 +262,18 @@ var Gogs = {};
}); });


$(window).on('hashchange', function (e) { $(window).on('hashchange', function (e) {
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
var m = window.location.hash.match(/^#diff-(\d+)(L\d+)\-(L\d+)$/);
var $list = $('.code-diff td.lines-num > span'); var $list = $('.code-diff td.lines-num > span');
var $first; var $first;
if (m) { if (m) {
$first = $list.filter('[rel=' + m[1] + ']');
selectRange($list, $first, $list.filter('[rel=' + m[2] + ']'));
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
selectRange($list, $first, $list.filter('[rel=diff-' + m[1] + m[3] + ']'));
$("html, body").scrollTop($first.offset().top - 200); $("html, body").scrollTop($first.offset().top - 200);
return; return;
} }
m = window.location.hash.match(/^#(L\d+)$/);
m = window.location.hash.match(/^#diff-(\d+)(L\d+)$/);
if (m) { if (m) {
$first = $list.filter('[rel=' + m[1] + ']');
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
selectRange($list, $first); selectRange($list, $first);
$("html, body").scrollTop($first.offset().top - 200); $("html, body").scrollTop($first.offset().top - 200);
} }


Loading…
Cancel
Save