From e9c1ad241b3f0a8a2043964a717be74998a0ef39 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Wed, 13 Sep 2017 12:55:48 -0500 Subject: [PATCH 1/3] Update stackhistory internal editor list before getting elements (prevent that posible corruptions raise an error.) --- spyder/widgets/editor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py index 5fc00f49816..e1c544e21d4 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] From 0d846cfce2ba342500d2f397b82dc9c1ee6e77dd Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Wed, 13 Sep 2017 12:56:11 -0500 Subject: [PATCH 2/3] Remove side efect of _get_previous_file_index. _get_previous_file_index shouldn't modify stack_history, the stack history will be modified when the file close and current_changed is raised Modifing stack_history in _get_previous_file_index cause corruptions in the history when the close of the file is cancelled. --- spyder/widgets/editor.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py index e1c544e21d4..b83b48532f6 100644 --- a/spyder/widgets/editor.py +++ b/spyder/widgets/editor.py @@ -1723,12 +1723,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): """ From 193c50d7d9453ea2c896620d4cccf33ddea31a6e Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 14 Sep 2017 07:50:04 -0500 Subject: [PATCH 3/3] Fix error refresh method call missing parenthesis. --- spyder/widgets/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py index b83b48532f6..29974a5ce48 100644 --- a/spyder/widgets/editor.py +++ b/spyder/widgets/editor.py @@ -308,7 +308,7 @@ def __getitem__(self, i): try: return self.id_list.index(self.history[i]) except ValueError: - self.refresh + self.refresh() raise IndexError def __delitem__(self, i):