]> source.dussan.org Git - gitea.git/commitdiff
fix diff lines highlighting
authorAlexey Makhov <makhov.alex@gmail.com>
Tue, 3 Feb 2015 20:53:34 +0000 (23:53 +0300)
committerAlexey Makhov <makhov.alex@gmail.com>
Wed, 4 Feb 2015 09:41:35 +0000 (12:41 +0300)
public/ng/js/gogs.js
public/ng/less/gogs/repository.less
templates/repo/diff.tmpl

index f0bb76330de579579115b82774e1ec05ef255d64..47c2e38fe15ff69df5102fcdd86e1cc3d5d864d6 100644 (file)
@@ -141,6 +141,7 @@ var Gogs = {};
     Gogs.renderCodeView = function () {
         function selectRange($list, $select, $from) {
             $list.removeClass('active');
+            $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));
@@ -153,21 +154,27 @@ var Gogs = {};
                     }
                     var classes = [];
                     for (i = a; i <= b; i++) {
-                        classes.push('.L' + 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);
                     return
                 }
             }
             $select.addClass('active');
+            $select.parents('tr').find('td').addClass('selected-line');
             $.changeHash('#' + $select.attr('rel'));
         }
 
         $(document).on('click', '.lines-num span', function (e) {
             var $select = $(this);
-            var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
-            selectRange($list, $list.filter('[rel=' + $select.attr('rel') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
+            var $list = $select.parent().siblings('.lines-code').parents().find('td.lines-num > span');
+            selectRange(
+                $list,
+                $list.filter('[rel=' + $select.attr('rel') + ']'),
+                (e.shiftKey && $list.filter('.active').length ? $list.filter('.active').eq(0) : null)
+            );
             $.deSelect();
         });
 
@@ -185,17 +192,17 @@ var Gogs = {};
 
         $(window).on('hashchange', function (e) {
             var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
-            var $list = $('.code-view ol.linenums > li');
+            var $list = $('.code-view td.lines-num > span');
             var $first;
             if (m) {
-                $first = $list.filter('.' + m[1]);
-                selectRange($list, $first, $list.filter('.' + m[2]));
+                $first = $list.filter('[rel=' + m[1] + ']');
+                selectRange($list, $first, $list.filter('[rel=' + m[2] + ']'));
                 $("html, body").scrollTop($first.offset().top - 200);
                 return;
             }
             m = window.location.hash.match(/^#(L\d+)$/);
             if (m) {
-                $first = $list.filter('.' + m[1]);
+                $first = $list.filter('[rel=' + m[1] + ']');
                 selectRange($list, $first);
                 $("html, body").scrollTop($first.offset().top - 200);
             }
index 291784298c7f370970aa0ba86457f8006a92cd0c..e48f5c87138b01050d57c1eed38ff1fe68ce1ea6 100644 (file)
                         background-color: #d1ffd6 !important;
                         border-color: #b4e2b4 !important;
                     }
+                    td.selected-line, td.selected-line pre {
+                        background-color: #ffffdd !important;
+                    }
                 }
                 &:hover {
                     td, pre {
index 8045351600e0fadd37d3b04aa6ddc462f24008d7..8becb006597ecdf32e8b84be30d57a11abfdf177 100644 (file)
                 <table>
                     <tbody>
                         {{range .Sections}}
-                        {{range .Lines}}
-                        <tr class="{{DiffLineTypeToStr .Type}}-code nl-1 ol-1">
+                        {{range $i, $line := .Lines}}
+                        <tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$i}} ol-{{$i}}">
                             <td class="lines-num lines-num-old">
-                                <span rel="L1">{{if .LeftIdx}}{{.LeftIdx}}{{end}}</span>
+                                <span rel="L{{$i}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
                             </td>
                             <td class="lines-num lines-num-new">
-                                <span rel="L1">{{if .RightIdx}}{{.RightIdx}}{{end}}</span>
+                                <span rel="L{{$i}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
                             </td>
                             
                             <td class="lines-code">
-                                <pre>{{.Content}}</pre>
+                                <pre>{{$line.Content}}</pre>
                             </td>
                         </tr>
                         {{end}}