about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2018-03-04 14:13:55 +0100
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2018-03-04 14:13:55 +0100
commit6f8fa8b5ef21792a69066500375b3643c50decfb (patch)
treea202cb51e8b173b66104536e12bd69ad15a6f936 /ranger
parent7dd423ca506ae0ae46be015d6e1564d2b24ae36a (diff)
downloadranger-6f8fa8b5ef21792a69066500375b3643c50decfb.tar.gz
Add the 'hint_collapse_threshold' that controls when the submaps are collapsed
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/rc.conf4
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/gui/widgets/view_base.py21
3 files changed, 21 insertions, 5 deletions
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 676090fb..fe00c7c0 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -216,6 +216,10 @@ set cd_tab_fuzzy false
 # disable this feature.
 set preview_max_size 0
 
+# The key hint lists up to this size have their sublists expanded.
+# Otherwise the submaps are replaced with "...".
+set hint_collapse_threshold 10
+
 # Add the highlighted file to the path in the titlebar
 set show_selection_in_titlebar true
 
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index d0b094d0..8b7364a2 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -45,6 +45,7 @@ ALLOWED_SETTINGS = {
     'freeze_files': bool,
     'global_inode_type_filter': str,
     'hidden_filter': str,
+    'hint_collapse_threshold' : int,
     'hostname_in_titlebar': bool,
     'idle_delay': int,
     'iterm2_font_width': int,
diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py
index b005f1d5..0878ab0f 100644
--- a/ranger/gui/widgets/view_base.py
+++ b/ranger/gui/widgets/view_base.py
@@ -132,7 +132,7 @@ class ViewBase(Widget, DisplayableContainer):  # pylint: disable=too-many-instan
             """
             from itertools import groupby
 
-            # groupby needs the list to be sorted
+            # groupby needs the list to be sorted.
             hints.sort(key=lambda t: t[0])
 
             def group_hints(hints):
@@ -147,13 +147,24 @@ class ViewBase(Widget, DisplayableContainer):  # pylint: disable=too-many-instan
                         in groupby(
                             hints,
                             key=first_key))
-            hints = sorted(
-                group_hints(hints),
-                key=lambda g: g[0][1])  # sort by the first action in group
+
+            grouped_hints = group_hints(hints)
+
+            # If there are too many hints, collapse the sublists.
+            if len(hints) > self.fm.settings.hint_collapse_threshold:
+                def first_key_in_group(group):
+                    return group[0][0][0]
+                grouped_hints = [[(first_key_in_group(hint_group), "...")]
+                               if len(hint_group) > 1
+                               else hint_group
+                               for hint_group in grouped_hints]
+
+            # Sort by the first action in group.
+            grouped_hints = sorted(grouped_hints, key=lambda g: g[0][1])
 
             def flatten(nested_list):
                 return [item for inner_list in nested_list for item in inner_list]
-            return flatten(hints)
+            return flatten(grouped_hints)
         hints = sort_hints(hints)
 
         hei = min(self.hei - 1, len(hints))