diff options
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodeformatter.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 582293ff10..89915daef5 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -455,6 +455,8 @@ void CodeFormatter::updateStateUntil(const QTextBlock &endBlock) { QStack<State> previousState = initialState(); QTextBlock it = endBlock.document()->firstBlock(); + + // find the first block that needs recalculation for (; it.isValid() && it != endBlock; it = it.next()) { TextBlockUserData *userData = BaseTextDocumentLayout::userData(it); CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData()); @@ -469,10 +471,47 @@ void CodeFormatter::updateStateUntil(const QTextBlock &endBlock) previousState = cppData->m_endState; } + + if (it == endBlock) + return; + + // update everthing until endBlock for (; it.isValid() && it != endBlock; it = it.next()) { - //qDebug() << "recalc line" << it.blockNumber() + 1; recalculateStateAfter(it); } + + // invalidate everything below by marking the state in endBlock as invalid + TextBlockUserData *userData = BaseTextDocumentLayout::userData(endBlock); + CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData()); + if (cppData) + cppData->setBlockRevision(-1); +} + +void CodeFormatter::updateLineStateChange(const QTextBlock &block) +{ + if (!block.isValid()) + return; + + QStack<State> oldEndState; + + TextBlockUserData *userData = BaseTextDocumentLayout::userData(block); + CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData()); + if (cppData) + oldEndState = cppData->m_endState; + + recalculateStateAfter(block); + + if (oldEndState.isEmpty() || oldEndState != cppData->m_endState) { + // invalidate everything below by marking the next block's state as invalid + QTextBlock next = block.next(); + if (!next.isValid()) + return; + + userData = BaseTextDocumentLayout::userData(next); + cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData()); + if (cppData) + cppData->setBlockRevision(-1); + } } CodeFormatter::State CodeFormatter::state(int belowTop) const |