about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/history.py10
-rw-r--r--ranger/core/actions.py8
-rw-r--r--ranger/core/tab.py3
3 files changed, 19 insertions, 2 deletions
diff --git a/ranger/container/history.py b/ranger/container/history.py
index 1f2c5a4b..8ba092bc 100644
--- a/ranger/container/history.py
+++ b/ranger/container/history.py
@@ -1,6 +1,8 @@
 # Copyright (C) 2009, 2010, 2011  Roman Zimbelmann <romanz@lavabit.com>
 # This software is distributed under the terms of the GNU GPL version 3.
 
+# TODO: rewrite to use deque instead of list
+
 class HistoryEmptyException(Exception):
 	pass
 
@@ -49,6 +51,14 @@ class History(object):
 		except IndexError:
 			self.add(item)
 
+	def rebase(self, other_history):
+		assert isinstance(other_history, History)
+		index_offset = len(self._history) - self._index
+		self._history[:self._index] = list(other_history._history)
+		if len(self._history) > self.maxlen:
+			self._history = self._history[-self.maxlen:]
+		self._index = len(self._history) - index_offset
+
 	def __len__(self):
 		return len(self._history)
 
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 24b115de..fe5bc68b 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -841,13 +841,17 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		previous_tab = self.thistab
 		try:
 			tab = self.tabs[name]
+			tab.enter_dir(tab.path, history=False)
 		except KeyError:
+			# create a new tab
 			if path:
 				tab = Tab(path)
 			else:
 				tab = Tab(self.thistab.path)
 			self.tabs[name] = tab
-		tab.enter_dir(tab.path)
+			tab.enter_dir(tab.path, history=True)
+			if previous_tab:
+				tab.inherit_history(previous_tab.history)
 		self.thistab = tab
 
 		if tab_has_changed:
@@ -877,7 +881,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 				if not name in self.tabs:
 					self.current_tab = name
 					self.tabs[name] = tab
-					tab.enter_dir(tab.path)
+					tab.enter_dir(tab.path, history=False)
 					self.thistab = tab
 					self.change_mode('normal')
 					self.signal_emit('tab.change', old=previous_tab,
diff --git a/ranger/core/tab.py b/ranger/core/tab.py
index e5605f28..153611df 100644
--- a/ranger/core/tab.py
+++ b/ranger/core/tab.py
@@ -96,6 +96,9 @@ class Tab(FileManagerAware, SettingsAware):
 		if self.history:
 			self.history.move(relative).go(history=False)
 
+	def inherit_history(self, other_history):
+		self.history.rebase(other_history)
+
 	def enter_dir(self, path, history = True):
 		"""Enter given path"""
 		# TODO: Ensure that there is always a self.thisdir