From 093c8b1a7b7656c82923539a4286606fd7ded4b5 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 25 Oct 2013 18:51:29 +0200 Subject: api.commands: improved tab-completion of :rename and others The list of items that you tab through is now constrained to non-hidden files and the order is the same as visible on the screen - starting from the current file. --- ranger/api/commands.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'ranger/api/commands.py') diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 305bab75..98b0a23a 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -273,22 +273,41 @@ class Command(FileManagerAware): rel_dirname = dirname(rel_dest) try: + directory = self.fm.get_directory(abs_dest) + # are we at the end of a directory? if rel_dest.endswith('/') or rel_dest == '': - _, dirnames, filenames = next(os.walk(abs_dest)) - names = dirnames + filenames + if directory.content_loaded: + # Take the order from the directory object + names = [f.basename for f in directory.files] + if self.fm.thisfile.basename in names: + i = names.index(self.fm.thisfile.basename) + names = names[i:] + names[:i] + else: + # Fall back to old method with "os.walk" + _, dirnames, filenames = next(os.walk(abs_dest)) + names = dirnames + filenames + names.sort() # are we in the middle of the filename? else: - _, dirnames, filenames = next(os.walk(abs_dirname)) - names = [name for name in (dirnames + filenames) \ - if name.startswith(rel_basename)] + if directory.content_loaded: + # Take the order from the directory object + names = [f.basename for f in directory.files \ + if f.basename.startswith(rel_basename)] + if self.fm.thisfile.basename in names: + i = names.index(self.fm.thisfile.basename) + names = names[i:] + names[:i] + else: + # Fall back to old method with "os.walk" + _, dirnames, filenames = next(os.walk(abs_dirname)) + names = [name for name in (dirnames + filenames) \ + if name.startswith(rel_basename)] + names.sort() except (OSError, StopIteration): # os.walk found nothing pass else: - names.sort() - # no results, return None if len(names) == 0: return -- cgit 1.4.1-2-gfad0