diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 79f9d1d1..495b3409 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2220,13 +2220,19 @@ def _insert_plain_text(self, cursor, text, flush=False): QtGui.QTextCursor.MoveAnchor) elif act.action == 'newline': - self.log.debug(self._prompt) - if cursor.block() != cursor.document().lastBlock(): + if ( + cursor.block() != cursor.document().lastBlock() + and not cursor.document() + .toPlainText() + .endswith(self._prompt) + ): cursor.movePosition(QtGui.QTextCursor.NextBlock) else: - cursor.movePosition(QtGui.QTextCursor.EndOfLine, - QtGui.QTextCursor.MoveAnchor) - cursor.insertText('\n') + cursor.movePosition( + QtGui.QTextCursor.EndOfLine, + QtGui.QTextCursor.MoveAnchor, + ) + cursor.insertText("\n") # simulate replacement mode if substring is not None: