Commit 5cd6ebfdfd94aa9745f2ca8e92c5ed24d6bc1afa
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
| |   |
| 1494 | 1494 | void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar) |
| 1495 | 1495 | { |
| 1496 | 1496 | Q_UNUSED(doc) |
| Q_UNUSED(typedChar) |
| 1498 | 1497 | |
| 1499 | 1498 | const TabSettings &ts = tabSettings(); |
| 1500 | 1499 | CppTools::QtStyleCodeFormatter codeFormatter(ts); |
| 1501 | 1500 | |
| 1502 | 1501 | codeFormatter.updateStateUntil(block); |
| 1503 | 1502 | 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; |
| } |
|
| 1504 | 1512 | ts.indentLine(block, depth); |
| 1505 | 1513 | } |
| 1506 | 1514 | |
| |   |
| 470 | 470 | return m_indentDepth; |
| 471 | 471 | } |
| 472 | 472 | |
| int CodeFormatter::indentForNewLineAfter(const QTextBlock &block) |
| { |
| restoreCurrentState(block); |
| return m_indentDepth; |
| } |
|
| 473 | 479 | void CodeFormatter::updateStateUntil(const QTextBlock &endBlock) |
| 474 | 480 | { |
| 475 | 481 | QStack<State> previousState = initialState(); |
| |   |
| 69 | 69 | void updateLineStateChange(const QTextBlock &block); |
| 70 | 70 | |
| 71 | 71 | int indentFor(const QTextBlock &block); |
| int indentForNewLineAfter(const QTextBlock &block); |
| 72 | 73 | |
| 73 | 74 | void setTabSize(int tabSize); |
| 74 | 75 | |