Commit 5cd6ebfd authored by Christian Kamm's avatar Christian Kamm
Browse files

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
parent 2989ac1d
......@@ -1494,13 +1494,21 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
const TabSettings &ts = tabSettings();
CppTools::QtStyleCodeFormatter codeFormatter(ts);
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)
ts.indentLine(block, depth);
......@@ -470,6 +470,12 @@ int CodeFormatter::indentFor(const QTextBlock &block)
return m_indentDepth;
int CodeFormatter::indentForNewLineAfter(const QTextBlock &block)
return m_indentDepth;
void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
QStack<State> previousState = initialState();
......@@ -69,6 +69,7 @@ public:
void updateLineStateChange(const QTextBlock &block);
int indentFor(const QTextBlock &block);
int indentForNewLineAfter(const QTextBlock &block);
void setTabSize(int tabSize);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment