From 67bbce7911b1ec10272ac017bf06852c2b50183d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com> Date: Thu, 3 Dec 2009 15:46:05 +0100 Subject: [PATCH] Fixed problem with indentation when auto-indent is turned off When auto-indent is turned off, Qt Creator uses a simplistic approach of copying the indentation string from the previous line. This was broken when the cursor was positioned inside the indentation, since this caused part of the indentation to go to the next line, which was then prepended with the copied indentation, in effect increasing the indentation for each new line. The solution here was to copy the indentation from the previous block only after inserting the new block, which causes the indentation of the previous line to be cut off by exactly the right amount to keep the indentation constant. Task-number: QTCREATORBUG-396 Reviewed-by: mae --- src/plugins/texteditor/basetexteditor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index db0fb807351..8f51ed65745 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -928,8 +928,10 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) cursor.insertBlock(); indent(document(), cursor, QChar::Null); } else { - QString previousBlockText = cursor.block().text(); cursor.insertBlock(); + + // After inserting the block, to avoid duplicating whitespace on the same line + const QString previousBlockText = cursor.block().previous().text(); cursor.insertText(ts.indentationString(previousBlockText)); } cursor.endEditBlock(); -- GitLab