mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:15:43 +01:00
new lines highlighting format
This commit is contained in:
parent
02c5bade0f
commit
01cef678a3
1 changed files with 20 additions and 14 deletions
|
@ -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 expr = new RegExp(/diff-(\d+)L(\d+)/);
|
||||||
var b = parseInt($from.attr('rel').substr(1));
|
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 = [];
|
$('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line');
|
||||||
for (i = a; i <= b; i++) {
|
var $selectedLines = $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf();
|
||||||
classes.push('[rel=L' + i + ']');
|
$selectedLines.find('td.lines-num > span').addClass('active')
|
||||||
}
|
$selectedLines.find('td').addClass('selected-line');
|
||||||
$list.filter(classes.join(',')).addClass('active');
|
$.changeHash('#diff-'+fromMatches[1]+'L' + linesIntToStr[a] + '-L' + linesIntToStr[b]);
|
||||||
$list.filter(classes.join(',')).parents('tr').find('td').addClass('selected-line');
|
|
||||||
$.changeHash('#L' + a + '-' + 'L' + 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] + ']');
|
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
|
||||||
selectRange($list, $first, $list.filter('[rel=' + 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…
Reference in a new issue