From 01cef678a352fc3c4d5e1c2258171c887a04925c Mon Sep 17 00:00:00 2001
From: Alexey Makhov <makhov.alex@gmail.com>
Date: Thu, 5 Feb 2015 10:49:04 +0300
Subject: [PATCH] new lines highlighting format

---
 public/ng/js/gogs.js | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js
index e9b44d6575..a6b9753e17 100644
--- a/public/ng/js/gogs.js
+++ b/public/ng/js/gogs.js
@@ -206,10 +206,18 @@ var Gogs = {};
     Gogs.renderDiffView = function () {
         function selectRange($list, $select, $from) {
             $list.removeClass('active');
+            $list.parents('tr').removeClass('end-selected-line');
             $list.parents('tr').find('td').removeClass('selected-line');
             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;
                 if (a != b) {
                     if (a > b) {
@@ -217,13 +225,11 @@ var Gogs = {};
                         a = b;
                         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
                 }
             }
@@ -256,18 +262,18 @@ var Gogs = {};
         });
 
         $(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 $first;
             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);
                 return;
             }
-            m = window.location.hash.match(/^#(L\d+)$/);
+            m = window.location.hash.match(/^#diff-(\d+)(L\d+)$/);
             if (m) {
-                $first = $list.filter('[rel=' + m[1] + ']');
+                $first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
                 selectRange($list, $first);
                 $("html, body").scrollTop($first.offset().top - 200);
             }