From 9d9687a63e1e07828f788c943b775185dac995f6 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 21 Jan 2010 03:58:24 +0100 Subject: commands: use deque in find command --- ranger/commands.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ranger/commands.py b/ranger/commands.py index a3137ddb..a1c2f028 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -13,6 +13,7 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. import os +from collections import deque from ranger.shared import FileManagerAware from ranger.gui.widgets import console_mode as cmode from ranger.ext.command_parser import LazyParser as parse @@ -215,17 +216,19 @@ class find(Command): except IndexError: return False - length = len(pwd.files) - for i in range(length): - actual_index = (pwd.pointer + i) % length - filename = pwd.files[actual_index].basename_lower + deq = deque(pwd.files) + deq.rotate(-pwd.pointer) + i = 0 + for fsobj in deq: + filename = fsobj.basename_lower if arg in filename: self.count += 1 if self.count == 1: - pwd.move(absolute=actual_index) + pwd.move(absolute=(pwd.pointer + i) % len(pwd.files)) self.fm.env.cf = pwd.pointed_obj if self.count > 1: return False + i += 1 return self.count == 1 -- cgit 1.4.1-2-gfad0