summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorlverweijen <lverweijen>2016-03-08 19:20:22 +0100
committerlverweijen <lverweijen>2016-03-08 19:29:50 +0100
commitd14d9386c006e5f802285056a42f3173080a1b95 (patch)
tree1d7e36d1f782bfdaa99a82791a39083878e9e216 /ranger
parent7ee4b45bd2619fb07c9b139940003224bedb1de3 (diff)
downloadranger-d14d9386c006e5f802285056a42f3173080a1b95.tar.gz
Make natural_sort's behaviour better defined
The old version relied on comparing integers to strings which is not
supported in Python 3 anymore and not a good practice in general anyway.
It was also the case that 'hello2' was ordered before 'hello' instead of
after, which I found to be non-intuitive.
Diffstat (limited to 'ranger')
-rw-r--r--ranger/container/fsobject.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py
index 1daf6d70..db6772ac 100644
--- a/ranger/container/fsobject.py
+++ b/ranger/container/fsobject.py
@@ -30,7 +30,7 @@ else:
     from string import maketrans
 _unsafe_chars = '\n' + ''.join(map(chr, range(32))) + ''.join(map(chr, range(128, 256)))
 _safe_string_table = maketrans(_unsafe_chars, '?' * len(_unsafe_chars))
-_extract_number_re = re.compile(r'(\d+)')
+_extract_number_re = re.compile(r'(\d+|\D)')
 
 def safe_path(path):
     return path.translate(_safe_string_table)
@@ -134,12 +134,12 @@ class FileSystemObject(FileManagerAware, SettingsAware):
 
     @lazy_property
     def basename_natural(self):
-        return [int(s) if s.isdigit() else s \
+        return [('0', int(s)) if s.isdigit() else (s, 0) \
                 for s in _extract_number_re.split(self.relative_path)]
 
     @lazy_property
     def basename_natural_lower(self):
-        return [int(s) if s.isdigit() else s \
+        return [('0', int(s)) if s.isdigit() else (s, 0) \
                 for s in _extract_number_re.split(self.relative_path_lower)]
 
     @lazy_property