From 3461f24de6d816aa4eab5de4ed6a019f80a61b41 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 26 May 2022 20:20:22 +0200 Subject: 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. --- ranger/gui/widgets/browsercolumn.py | 12 ++++++++++-- 1 file 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 -- cgit 1.4.1-2-gfad0