diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py index 1b04e5b9faf..b2391d9770e 100644 --- a/spyder/widgets/editor.py +++ b/spyder/widgets/editor.py @@ -304,7 +304,12 @@ def __len__(self): return len(self.history) def __getitem__(self, i): - return self.id_list.index(self.history[i]) + self._update_id_list() + try: + return self.id_list.index(self.history[i]) + except ValueError: + self.refresh() + raise IndexError def __delitem__(self, i): del self.history[i] @@ -1759,12 +1764,11 @@ def current_changed(self, index): pass def _get_previous_file_index(self): - if len(self.stack_history) > 1: - last = len(self.stack_history)-1 - w_id = self.stack_history.pop(last) - self.stack_history.insert(0, w_id) - - return self.stack_history[last] + """Return the penultimate element of the stack history.""" + try: + return self.stack_history[-2] + except IndexError: + return None def tab_navigation_mru(self, forward=True): """