Commits

Henning Schröder committed e97fdc3

optimize name lookup for whitespace mode

  • Participants
  • Parent commits df48980

Comments (0)

Files changed (1)

File codeaide/modes/visualhelper.py

         get_user_data = self.textedit.user_data
         painter_set_pen = painter.setPen
         painter_draw_rect = painter.drawRect
+        space_pen = self.space_pen
+        all_space_pen = self.all_space_pen
+        tab_pen = self.tab_pen
         w = self.char_width
-        dx = (w/2) + 0
+        dx = (w / 2) + 1
         for vb in self.textedit.visible_blocks:
             if not rect_intersects(vb.rect):
                 continue
             y = vb.top + vb.height / 2 - 1
-            positions = get_user_data(vb.block).get("char_map", {}).get(" ", [])
-            if len(positions) == vb.block.text().length():
-                painter_set_pen(self.all_space_pen)
+            space_positions = get_user_data(vb.block).get("char_map", {}).get(" ", [])
+            tab_positions = get_user_data(vb.block).get("char_map", {}).get("\t", [])
+            if len(space_positions) + len(tab_positions) == vb.block.text().length():
+                # line only consists of whitespace
+                painter_set_pen(all_space_pen)
             else:
-                painter_set_pen(self.space_pen)
-            for pos, end in positions:
+                painter_set_pen(space_pen)
+            for pos, end in space_positions:
                 # XXX: better use drawPixmap?
-                painter_draw_rect(dx+pos * w, y, 1,1)
-            positions = get_user_data(vb.block).get("char_map", {}).get("\t", [])
-            if positions:
-                painter_set_pen(self.tab_pen)
-                for pos, end in positions:
-                    painter_draw_rect(dx+pos * w, y, 1,1)
+                painter_draw_rect(dx + pos * w, y, 1, 1)
 
+            if tab_positions:
+                painter_set_pen(tab_pen)
+                for pos, end in tab_positions:
+                    painter_draw_rect(dx + pos * w, y, 1, 1)
+