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:
Artem Sokolovskii
2024-08-08 17:05:40 +02:00
parent 4ec324af0b
commit 343e206b48
2 changed files with 16 additions and 2 deletions

View File

@@ -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
const int lastTokenEnd = tokens.last().utf16charsEnd();
if (text.length() > lastTokenEnd)
@@ -284,7 +299,7 @@ void CppHighlighter::highlightBlock(const QString &text)
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
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;
TextDocumentLayout::setExpectedRawStringSuffix(currentBlock(),

View File

@@ -3011,7 +3011,6 @@ void FakeVimTester::test_vim_code_folding()
"}" N
"");
NOT_IMPLEMENTED
// Opening folds recursively isn't supported (previous position in fold isn't restored).
}