Commit 5cd6ebfdfd94aa9745f2ca8e92c5ed24d6bc1afa

  • avatar
  • ckamm
  • Wed Sep 08 16:22:23 CEST 2010
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
  
14941494void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
14951495{
14961496 Q_UNUSED(doc)
1497 Q_UNUSED(typedChar)
14981497
14991498 const TabSettings &ts = tabSettings();
15001499 CppTools::QtStyleCodeFormatter codeFormatter(ts);
15011500
15021501 codeFormatter.updateStateUntil(block);
15031502 const int depth = codeFormatter.indentFor(block);
1503
1504 // only reindent the current line when typing electric characters if the
1505 // indent is the same it would be if the line were empty
1506 if (isElectricCharacter(typedChar)) {
1507 const int newlineIndent = codeFormatter.indentForNewLineAfter(block.previous());
1508 if (ts.indentationColumn(block.text()) != newlineIndent)
1509 return;
1510 }
1511
15041512 ts.indentLine(block, depth);
15051513}
15061514
  
470470 return m_indentDepth;
471471}
472472
473int CodeFormatter::indentForNewLineAfter(const QTextBlock &block)
474{
475 restoreCurrentState(block);
476 return m_indentDepth;
477}
478
473479void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
474480{
475481 QStack<State> previousState = initialState();
  
6969 void updateLineStateChange(const QTextBlock &block);
7070
7171 int indentFor(const QTextBlock &block);
72 int indentForNewLineAfter(const QTextBlock &block);
7273
7374 void setTabSize(int tabSize);
7475