about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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))