about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2022-05-26 20:20:22 +0200
committertoonn <toonn@toonn.io>2022-05-26 23:42:33 +0200
commit3461f24de6d816aa4eab5de4ed6a019f80a61b41 (patch)
tree7da756d652dd356afcdadaf3b6faa9f9487a7c7c
parent9b47c41a3717ebcb7deeccd0ba947eb50069634e (diff)
downloadranger-3461f24de6d816aa4eab5de4ed6a019f80a61b41.tar.gz
browsercolumn: Fix relative line number width
For relative line numbers the width that actually matters is the width
for all the displayed line numbers. The width of the largest index of
the displayed files doesn't matter. Only the width of the relative
indices and the width of the currently highlighted item's index, unless
`relative_current_zero` is enabled.
-rw-r--r--ranger/gui/widgets/browsercolumn.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 59f2622d..c65bf018 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -273,12 +273,20 @@ class BrowserColumn(Pager):  # pylint: disable=too-many-instance-attributes
 
         copied = [f.path for f in self.fm.copy_buffer]
 
+        selected_i = self._get_index_of_selected_file()
+
         # Set the size of the linum text field to the number of digits in the
         # visible files in directory.
-        linum_text_len = len(str(self.scroll_begin + self.hei - 1))
+        scroll_end = self.scroll_begin + self.hei - 1
+        if self.settings.line_numbers.lower() == "relative":
+            linum_text_len = len(str(max(selected_i - self.scroll_begin,
+                                         scroll_end - selected_i)))
+            if not self.settings.relative_current_zero:
+                linum_text_len = max(len(str(selected_i)), linum_text_len)
+        else:
+            linum_text_len = len(str(scroll_end))
         linum_format = "{0:>" + str(linum_text_len) + "}"
 
-        selected_i = self._get_index_of_selected_file()
         for line in range(self.hei):
             i = line + self.scroll_begin