[PATCH] diff view: improve appearance of line numbers

Andrew Shadura andrew at shadura.me
Tue May 5 12:15:31 EDT 2015


# HG changeset patch
# User Andrew Shadura <andrew at shadura.me>
# Date 1430842380 -7200
#      Tue May 05 18:13:00 2015 +0200
# Node ID c49fd027ae6491270795db939dcd724d6e29b3fd
# Parent  4347c8958b9442dac9744e3f4e1e2282ffa25ce7
diff view: improve appearance of line numbers

 * display the ellipsis just once and centered
 * expand column width as needed to accomodate longer numbers
 * enable box-sizing: border-box for the number links to
   make it easier to set paddings

diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py
--- a/kallithea/lib/diffs.py
+++ b/kallithea/lib/diffs.py
@@ -642,6 +642,7 @@ class DiffProcessor(object):
 
     def as_html(self, table_class='code-difftable', line_class='line',
                 old_lineno_class='lineno old', new_lineno_class='lineno new',
+                no_lineno_class='lineno',
                 code_class='code', enable_comments=False, parsed_lines=None):
         """
         Return given diff as html table with customized css classes
@@ -693,6 +694,8 @@ class DiffProcessor(object):
                                 change['old_lineno'])
                     cond_new = (change['new_lineno'] != '...' and
                                 change['new_lineno'])
+                    no_lineno = (change['old_lineno'] == '...' and
+                                 change['new_lineno'] == '...')
                     if cond_old:
                         anchor_old_id = 'id="%s"' % anchor_old
                     if cond_new:
@@ -700,9 +703,10 @@ class DiffProcessor(object):
                     ###########################################################
                     # OLD LINE NUMBER
                     ###########################################################
-                    _html.append('''\t<td %(a_id)s class="%(olc)s">''' % {
+                    _html.append('''\t<td %(a_id)s class="%(olc)s" %(colspan)s>''' % {
                         'a_id': anchor_old_id,
-                        'olc': old_lineno_class
+                        'olc': no_lineno_class if no_lineno else old_lineno_class,
+                        'colspan': 'colspan="2"' if no_lineno else ''
                     })
 
                     _html.append('''%(link)s''' % {
@@ -714,16 +718,17 @@ class DiffProcessor(object):
                     # NEW LINE NUMBER
                     ###########################################################
 
-                    _html.append('''\t<td %(a_id)s class="%(nlc)s">''' % {
-                        'a_id': anchor_new_id,
-                        'nlc': new_lineno_class
-                    })
+                    if not no_lineno:
+                        _html.append('''\t<td %(a_id)s class="%(nlc)s">''' % {
+                            'a_id': anchor_new_id,
+                            'nlc': new_lineno_class
+                        })
 
-                    _html.append('''%(link)s''' % {
-                        'link': _link_to_if(True, change['new_lineno'],
-                                            '#%s' % anchor_new)
-                    })
-                    _html.append('''</td>\n''')
+                        _html.append('''%(link)s''' % {
+                            'link': _link_to_if(True, change['new_lineno'],
+                                                '#%s' % anchor_new)
+                        })
+                        _html.append('''</td>\n''')
                     ###########################################################
                     # CODE
                     ###########################################################
diff --git a/kallithea/public/css/style.css b/kallithea/public/css/style.css
--- a/kallithea/public/css/style.css
+++ b/kallithea/public/css/style.css
@@ -4906,7 +4906,6 @@ table.code-difftable td.code pre i {
 table.code-difftable .lineno {
     padding-left: 2px;
     padding-right: 2px !important;
-    text-align: right;
     width: 30px;
     -moz-user-select: none;
     -webkit-user-select: none;
@@ -4915,20 +4914,24 @@ table.code-difftable .lineno {
     border-top: 0px solid #CCC !important;
     border-bottom: none !important;
     vertical-align: middle !important;
+    text-align: center;
 }
 table.code-difftable .lineno.new {
+    text-align: right;
 }
 table.code-difftable .lineno.old {
+    text-align: right;
 }
 table.code-difftable .lineno a {
     color: #aaa !important;
     font: 11px Consolas, Monaco, Inconsolata, Liberation Mono, monospace !important;
     letter-spacing: -1px;
-    text-align: right;
+    padding-left: 10px;
     padding-right: 8px;
+    box-sizing: border-box;
     cursor: pointer;
     display: block;
-    width: 30px;
+    width: 100%;
 }
 
 table.code-difftable .lineno-inline {


More information about the kallithea-general mailing list