diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index 71e7fe1..d04911a 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -884,15 +884,16 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): the prompt region. """ # Select and remove all text below the input buffer. - _temp_buffer_filled = False cursor = self._get_prompt_cursor() prompt = self._continuation_prompt.lstrip() - while cursor.movePosition(QtGui.QTextCursor.NextBlock): - temp_cursor = QtGui.QTextCursor(cursor) - temp_cursor.select(QtGui.QTextCursor.BlockUnderCursor) - text = temp_cursor.selection().toPlainText().lstrip() - if not text.startswith(prompt): - break + if(self._temp_buffer_filled): + self._temp_buffer_filled = False + while cursor.movePosition(QtGui.QTextCursor.NextBlock): + temp_cursor = QtGui.QTextCursor(cursor) + temp_cursor.select(QtGui.QTextCursor.BlockUnderCursor) + text = temp_cursor.selection().toPlainText().lstrip() + if not text.startswith(prompt): + break else: # We've reached the end of the input buffer and no text follows. return @@ -945,7 +946,7 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): self._control.moveCursor(QtGui.QTextCursor.End) self._control.setTextCursor(cursor) - _temp_buffer_filled = True + self._temp_buffer_filled = True def _context_menu_make(self, pos):