From 902bff95fd76b75e7c9c7887d86529d979f5578a Mon Sep 17 00:00:00 2001 From: Florian Wagner Date: Thu, 13 Aug 2015 14:48:59 +0200 Subject: [PATCH] fixes #2614 --- spyderlib/widgets/sourcecode/codeeditor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spyderlib/widgets/sourcecode/codeeditor.py b/spyderlib/widgets/sourcecode/codeeditor.py index d936bd45305..8a2af2d4ad9 100644 --- a/spyderlib/widgets/sourcecode/codeeditor.py +++ b/spyderlib/widgets/sourcecode/codeeditor.py @@ -1883,6 +1883,7 @@ def fix_indent(self, forward=True, comment_or_string=False): # find the line that contains our scope diff = 0 add_indent = False + prevline = None for prevline in range(block_nb-1, -1, -1): cursor.movePosition(QTextCursor.PreviousBlock) prevtext = to_text_string(cursor.block().text()).rstrip() @@ -1903,6 +1904,10 @@ def fix_indent(self, forward=True, comment_or_string=False): break indent = self.get_block_indentation(block_nb) + + if not prevline: + return False + correct_indent = self.get_block_indentation(prevline) if add_indent: