summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-05 23:52:59 +0100
committerhut <hut@lavabit.com>2009-12-05 23:52:59 +0100
commit4162b636289f065b056e180389456d9f30ee796c (patch)
tree6eafd457c5f1c4deb8cf8cf10689ff394116a750
parent22bb7e358ccd6efc58c38b8703b6818131905a75 (diff)
downloadranger-4162b636289f065b056e180389456d9f30ee796c.tar.gz
integrated history into environment class
-rw-r--r--ranger/environment.py36
1 files changed, 6 insertions, 30 deletions
diff --git a/ranger/environment.py b/ranger/environment.py
index be39fbb6..d8a535ab 100644
--- a/ranger/environment.py
+++ b/ranger/environment.py
@@ -5,6 +5,7 @@ class Environment():
 	# A collection of data which is relevant for more than
 	# one class.
 	def __init__(self, path, opt):
+		from ranger.history import History
 		self.path = abspath(expanduser(path))
 		self.opt = opt
 		self.pathway = ()
@@ -15,8 +16,7 @@ class Environment():
 		self.keybuffer = ()
 		self.copy = None
 		self.termsize = (24, 80)
-		self.history = []
-		self.history_position = -1
+		self.history = History(opt['max_history_size'])
 
 	def key_append(self, key):
 		self.keybuffer += (key, )
@@ -58,35 +58,11 @@ class Environment():
 			last_path = path
 	
 	def history_go(self, relative):
-		if not self.history:
-			return
-
-		if self.history_position == -1:
-			if relative > 0:
-				return
-			elif relative < 0:
-				self.history_position = max( 0, len(self.history) - 1 + relative )
-		else:
-			self.history_position += relative
-			if self.history_position < 0:
-				self.history_position = 0
-
-		if self.history_position >= len(self.history) - 1:
-			self.history_position = -1
-
-		self.enter_dir(self.history[self.history_position], history=False)
-
-	def history_add(self, path):
-		if self.opt['max_history_size']:
-			if len(self.history) > self.history_position > (-1):
-				self.history = self.history[0 : self.history_position + 1]
-			if not self.history or (self.history and self.history[-1] != path):
-				self.history_position = -1
-				self.history.append(path)
-			if len(self.history) > self.opt['max_history_size']:
-				self.history.pop(0)
+		if self.history:
+			self.enter_dir(self.history.move(relative))
 
 	def enter_dir(self, path, history = True):
+		if path is None: return
 		path = str(path)
 
 		# get the absolute path
@@ -122,7 +98,7 @@ class Environment():
 		self.cf = self.pwd.pointed_file
 
 		if history:
-			self.history_add(path)
+			self.history.add(path)
 
 		return True
 
Agaram <vc@akkartik.com> 2016-08-17 12:20:48 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2016-08-17 12:20:48 -0700 3214' href='/akkartik/mu/commit/044space_surround.cc?h=hlt&id=e4fc73b1d73d7731f96e4c7692b96751ce1128bd'>e4fc73b1 ^
8f1db754 ^



b24eb476 ^

23d3a022 ^
263e6b2a ^
8f1db754 ^

b24eb476 ^
d0e29245 ^
82ac0b7e ^
23d3a022 ^


8f1db754 ^

b24eb476 ^
6c96a437 ^
0487a30e ^
ae256ea1 ^
9dcbec39 ^
ae256ea1 ^
0487a30e ^
8f1db754 ^


047296d8 ^

1ead3562 ^
192d59d3 ^
047296d8 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70