summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-09-08 16:18:58 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-09-08 16:22:23 +0200
commit5cd6ebfdfd94aa9745f2ca8e92c5ed24d6bc1afa (patch)
tree9fa31d3086c2097aca8c21fe308919616c247329 /src/plugins
parent2989ac1d69ac6fff8e27e881ea3d654425691c2a (diff)
downloadqt-creator-5cd6ebfdfd94aa9745f2ca8e92c5ed24d6bc1afa.tar.gz
C++: Only reindent on electric characters if indent wasn't user-changed.
This should make the indenter less strict and annoying for non-standard indentation styles. Reviewed-by: Roberto Raggi
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp10
-rw-r--r--src/plugins/cpptools/cppcodeformatter.cpp6
-rw-r--r--src/plugins/cpptools/cppcodeformatter.h1
3 files changed, 16 insertions, 1 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 40294cde5e..ec1aafc753 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -1494,13 +1494,21 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
{
Q_UNUSED(doc)
- Q_UNUSED(typedChar)
const TabSettings &ts = tabSettings();
CppTools::QtStyleCodeFormatter codeFormatter(ts);
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
+
+ // only reindent the current line when typing electric characters if the
+ // indent is the same it would be if the line were empty
+ if (isElectricCharacter(typedChar)) {
+ const int newlineIndent = codeFormatter.indentForNewLineAfter(block.previous());
+ if (ts.indentationColumn(block.text()) != newlineIndent)
+ return;
+ }
+
ts.indentLine(block, depth);
}
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp
index a162488088..89c9d85f5e 100644
--- a/src/plugins/cpptools/cppcodeformatter.cpp
+++ b/src/plugins/cpptools/cppcodeformatter.cpp
@@ -470,6 +470,12 @@ int CodeFormatter::indentFor(const QTextBlock &block)
return m_indentDepth;
}
+int CodeFormatter::indentForNewLineAfter(const QTextBlock &block)
+{
+ restoreCurrentState(block);
+ return m_indentDepth;
+}
+
void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
{
QStack<State> previousState = initialState();
diff --git a/src/plugins/cpptools/cppcodeformatter.h b/src/plugins/cpptools/cppcodeformatter.h
index a9a9aa7e06..e0365cb5cf 100644
--- a/src/plugins/cpptools/cppcodeformatter.h
+++ b/src/plugins/cpptools/cppcodeformatter.h
@@ -69,6 +69,7 @@ public:
void updateLineStateChange(const QTextBlock &block);
int indentFor(const QTextBlock &block);
+ int indentForNewLineAfter(const QTextBlock &block);
void setTabSize(int tabSize);