C++ indenter: Require explicit state update requests.

This will allow much faster indenting of selected areas as the state
doesn't have to be checked again for every line.
This commit is contained in:
Christian Kamm
2010-07-06 13:52:49 +02:00
parent c2a3346716
commit 8dbbf9be92
4 changed files with 6 additions and 4 deletions
+1
View File
@@ -1539,6 +1539,7 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
codeFormatter.setIndentDeclarationMembers(true);
}
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
ts.indentLine(block, depth);
}
+2 -3
View File
@@ -446,12 +446,12 @@ int CodeFormatter::indentFor(const QTextBlock &block)
{
// qDebug() << "indenting for" << block.blockNumber() + 1;
requireStatesUntil(block);
restoreBlockState(block.previous());
correctIndentation(block);
return m_indentDepth;
}
void CodeFormatter::requireStatesUntil(const QTextBlock &endBlock)
void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
{
QStack<State> previousState = initialState();
QTextBlock it = endBlock.document()->firstBlock();
@@ -473,7 +473,6 @@ void CodeFormatter::requireStatesUntil(const QTextBlock &endBlock)
//qDebug() << "recalc line" << it.blockNumber() + 1;
recalculateStateAfter(it);
}
restoreBlockState(endBlock.previous());
}
CodeFormatter::State CodeFormatter::state(int belowTop) const
+1 -1
View File
@@ -28,6 +28,7 @@ public:
CodeFormatter();
virtual ~CodeFormatter();
void updateStateUntil(const QTextBlock &block);
int indentFor(const QTextBlock &block);
void setTabSize(int tabSize);
@@ -138,7 +139,6 @@ protected:
bool isBracelessState(int type) const;
private:
void requireStatesUntil(const QTextBlock &block);
void recalculateStateAfter(const QTextBlock &block);
void storeBlockState(const QTextBlock &block);
void restoreBlockState(const QTextBlock &block);
@@ -89,6 +89,8 @@ void checkIndent(QList<Line> data, int style = 0)
formatter.setIndentDeclarationBraces(true);
}
formatter.updateStateUntil(document.lastBlock());
int i = 0;
foreach (const Line &l, data) {
if (l.expectedIndent != -1) {