about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-17 19:35:15 +0100
committerhut <hut@lavabit.com>2009-12-17 19:35:15 +0100
commit3dbefa71785bf61b8f28d4a780064f3f4e04dcb5 (patch)
treed2272b52303287ece416c33d568d24f15234ff84
parent16246965082ce5d319f5cef07da3ff533ca50cc2 (diff)
downloadranger-3dbefa71785bf61b8f28d4a780064f3f4e04dcb5.tar.gz
extended history by a couple of methods
-rw-r--r--ranger/container/history.py26
-rw-r--r--test/tc_history.py17
2 files changed, 33 insertions, 10 deletions
diff --git a/ranger/container/history.py b/ranger/container/history.py
index bd9a575f..355c7c72 100644
--- a/ranger/container/history.py
+++ b/ranger/container/history.py
@@ -11,16 +11,31 @@ class History(object):
 		if len(self.history) == 0 or self.history[-1] != item:
 			self.history.append(item)
 			self.history_forward.clear()
+	
+	def modify(self, item):
+		try:
+			self.history[-1] = item
+		except IndexError:
+			raise HistoryEmptyException
 
 	def __len__(self):
 		return len(self.history)
 
-	def top(self):
+	def current(self):
 		try:
 			return self.history[-1]
 		except IndexError:
 			raise HistoryEmptyException()
 
+	def top(self):
+		try:
+			return self.history_forward[0]
+		except IndexError:
+			try:
+				return self.history[-1]
+			except IndexError:
+				raise HistoryEmptyException()
+
 	def bottom(self):
 		try:
 			return self.history[0]
@@ -30,7 +45,7 @@ class History(object):
 	def back(self):
 		if len(self.history) > 1:
 			self.history_forward.append( self.history.pop() )
-		return self.top()
+		return self.current()
 
 	def move(self, n):
 		if n > 0:
@@ -47,4 +62,9 @@ class History(object):
 	def forward(self):
 		if len(self.history_forward) > 0:
 			self.history.append( self.history_forward.pop() )
-		return self.top()
+		return self.current()
+
+	def fast_forward(self):
+		if self.history_forward:
+			self.history.extend(self.history_forward)
+			self.history_forward.clear()
diff --git a/test/tc_history.py b/test/tc_history.py
index e3377532..18f71e35 100644
--- a/test/tc_history.py
+++ b/test/tc_history.py
@@ -13,23 +13,26 @@ class Test(TestCase):
 
 		hist.back()
 
-		self.assertEqual(4, hist.top())
+		self.assertEqual(4, hist.current())
 		self.assertEqual([3,4], list(hist))
 
+		self.assertEqual(5, hist.top())
+
 		hist.back()
-		self.assertEqual(3, hist.top())
+		self.assertEqual(3, hist.current())
 		self.assertEqual([3], list(hist))
 
-		# no change if top == bottom
-		self.assertEqual(hist.top(), hist.bottom())
-		last_top = hist.top()
+		# no change if current == bottom
+		self.assertEqual(hist.current(), hist.bottom())
+		last = hist.current()
 		hist.back()
-		self.assertEqual(hist.top(), last_top)
+		self.assertEqual(hist.current(), last)
 
+		self.assertEqual(5, hist.top())
 
 		hist.forward()
 		hist.forward()
-		self.assertEqual(5, hist.top())
+		self.assertEqual(5, hist.current())
 		self.assertEqual([3,4,5], list(hist))