forked from qt-creator/qt-creator
Syntaxhighlighter: Fix folding for function definition
The issue was: when the user removes the function definition and insert it back folding isn't changed. Now it triggers rehighlighting of the next line. Change-Id: I5dcc67ed2e09a20d54e3a38c9605a4a24ad79177 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -264,6 +264,21 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rehighlight the next block if it contains a folding marker since we move the folding
|
||||||
|
// marker in some cases and we need to rehighlight the next block to update this floding indent
|
||||||
|
int rehighlightNextBlock = 0;
|
||||||
|
if (const QTextBlock nextBlock = currentBlock().next(); nextBlock.isValid()) {
|
||||||
|
if (const auto nextData = TextDocumentLayout::textUserData(nextBlock)) {
|
||||||
|
if (const auto foldingCheckData = TextDocumentLayout::textUserData(nextBlock.next())) {
|
||||||
|
if (foldingCheckData->foldingIndent() > nextData->foldingIndent()) {
|
||||||
|
static const int rehighlightNextBlockMask = 1 << 24;
|
||||||
|
if (!(currentBlockState() & rehighlightNextBlockMask))
|
||||||
|
rehighlightNextBlock = rehighlightNextBlockMask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mark the trailing white spaces
|
// mark the trailing white spaces
|
||||||
const int lastTokenEnd = tokens.last().utf16charsEnd();
|
const int lastTokenEnd = tokens.last().utf16charsEnd();
|
||||||
if (text.length() > lastTokenEnd)
|
if (text.length() > lastTokenEnd)
|
||||||
@@ -284,7 +299,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
||||||
|
|
||||||
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
||||||
setCurrentBlockState((braceDepth << 8) | tokenize.state());
|
setCurrentBlockState(rehighlightNextBlock | (braceDepth << 8) | tokenize.state());
|
||||||
qCDebug(highlighterLog) << "storing brace depth" << braceDepth << "and folding indent" << foldingIndent;
|
qCDebug(highlighterLog) << "storing brace depth" << braceDepth << "and folding indent" << foldingIndent;
|
||||||
|
|
||||||
TextDocumentLayout::setExpectedRawStringSuffix(currentBlock(),
|
TextDocumentLayout::setExpectedRawStringSuffix(currentBlock(),
|
||||||
|
@@ -3011,7 +3011,6 @@ void FakeVimTester::test_vim_code_folding()
|
|||||||
"}" N
|
"}" N
|
||||||
"");
|
"");
|
||||||
|
|
||||||
NOT_IMPLEMENTED
|
|
||||||
// Opening folds recursively isn't supported (previous position in fold isn't restored).
|
// Opening folds recursively isn't supported (previous position in fold isn't restored).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user