[meld] gutterrendererchunk: Simplify whether-to-draw logic for chunk lines



commit 9f6be510d5f45d76f23ccb7f595a857043c3ba8c
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Oct 1 11:12:04 2016 +1000

    gutterrendererchunk: Simplify whether-to-draw logic for chunk lines

 meld/gutterrendererchunk.py |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/meld/gutterrendererchunk.py b/meld/gutterrendererchunk.py
index 8b2edd9..a01549e 100644
--- a/meld/gutterrendererchunk.py
+++ b/meld/gutterrendererchunk.py
@@ -56,21 +56,26 @@ class MeldGutterRenderer(object):
         if not chunk:
             return
 
+        is_first_line = line == chunk[1]
+        is_last_line = line == chunk[2] - 1
+        if not (is_first_line or is_last_line):
+            # Only paint for the first and last lines of a chunk
+            return
+
         x = background_area.x - 1
         y = background_area.y
         width = background_area.width + 2
         height = 1 if chunk[1] == chunk[2] else background_area.height
 
-        if line == chunk[1] or line == chunk[2] - 1:
-            context.set_line_width(1.0)
-            context.set_source_rgba(*self.line_colors[chunk[0]])
-            if line == chunk[1]:
-                context.move_to(x, y + 0.5)
-                context.rel_line_to(width, 0)
-            if line == chunk[2] - 1:
-                context.move_to(x, y - 0.5 + height)
-                context.rel_line_to(width, 0)
-            context.stroke()
+        context.set_line_width(1.0)
+        context.set_source_rgba(*self.line_colors[chunk[0]])
+        if is_first_line:
+            context.move_to(x, y + 0.5)
+            context.rel_line_to(width, 0)
+        if is_last_line:
+            context.move_to(x, y - 0.5 + height)
+            context.rel_line_to(width, 0)
+        context.stroke()
 
 
 class GutterRendererChunkAction(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]