summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAbdo Roig-Maranges <abdo.roig@gmail.com>2013-03-21 13:24:36 +0100
committerhut <hut@lavabit.com>2013-03-24 15:00:45 +0100
commit4b3b9e594faf539d96814bfca605405dce7d8086 (patch)
tree40dc04bb21ce62dcc3a552da57b388c11f831b39
parent36a8688271953fdfffb5bd0bae967cde0b675b05 (diff)
downloadranger-4b3b9e594faf539d96814bfca605405dce7d8086.tar.gz
Fix Issue #80 that crashed ranger when resized too small
This fixes Issue #80 and cleans up the code a bit so this particular
fragment is more readable.
-rw-r--r--ranger/gui/widgets/browsercolumn.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index a4ba7eea..d705e6ba 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -265,27 +265,33 @@ class BrowserColumn(Pager):
             # colorscheme, to compute the curses attribute.
             predisplay_left = []
             predisplay_right = []
-
-            predisplay_left += self._draw_tagged_display(tagged, tagged_marker)
-            predisplay_right += self._draw_vcsstring_display(drawn)
-            space = self.wid - self._total_len(predisplay_left) - \
-                    self._total_len(predisplay_right)
-
-            # If not enough space
-            if space <= 2:
-                del predisplay_right[:]
-                del predisplay_left[:]
-
+            space = self.wid
+
+            # selection mark
+            tagmark = self._draw_tagged_display(tagged, tagged_marker)
+            tagmarklen = self._total_len(tagmark)
+            if space - tagmarklen > 2:
+                predisplay_left += tagmark
+                space -= tagmarklen
+
+            # vcs data
+            vcsstring = self._draw_vcsstring_display(drawn)
+            vcsstringlen = self._total_len(vcsstring)
+            if space - vcsstringlen > 2:
+                predisplay_right += vcsstring
+                space -= vcsstringlen
+
+            # info string
             infostring = self._draw_infostring_display(drawn, space)
-            space -= self._total_len(infostring)
-
-            predisplay_left += self._draw_text_display(text, space)
-            space = self.wid - self._total_len(predisplay_left) - \
-                    self._total_len(predisplay_right)
+            infostringlen = self._total_len(infostring)
+            if space - infostringlen > 2:
+                predisplay_right = infostring + predisplay_right
+                space -= infostringlen
 
-            predisplay_right = infostring + predisplay_right
-            space = self.wid - self._total_len(predisplay_left) - \
-                    self._total_len(predisplay_right)
+            textstring = self._draw_text_display(text, space)
+            textstringlen = self._total_len(textstring)
+            predisplay_left += textstring
+            space -= textstringlen
 
             if space > 0:
                 predisplay_left.append([' ' * space, []])
@@ -314,9 +320,9 @@ class BrowserColumn(Pager):
 
     def _draw_text_display(self, text, space):
         wtext = WideString(text)
+        wellip = WideString(self.ellipsis[self.settings.unicode_ellipsis])
         if len(wtext) > space:
-            wtext = wtext[:max(0, space - 1)] + \
-                self.ellipsis[self.settings.unicode_ellipsis]
+            wtext = wtext[:max(0, space - len(wellip))] + wellip
 
         return [[str(wtext), []]]