forked from qt-creator/qt-creator
TextEditor: fix highlighting after removing line
We cannot reconstruct the correct initial state for highlighting when deleting a line if we generally save the after highlight state to the next line. Change-Id: I7d5f727f6b7c8340ac7f5436046cd0f1ad17ebd2 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -279,15 +279,24 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QTextBlock block = currentBlock();
|
QTextBlock block = currentBlock();
|
||||||
KSyntaxHighlighting::State state;
|
const QTextBlock previousBlock = block.previous();
|
||||||
TextDocumentLayout::setBraceDepth(block, TextDocumentLayout::braceDepth(block.previous()));
|
TextDocumentLayout::setBraceDepth(block, TextDocumentLayout::braceDepth(previousBlock));
|
||||||
|
KSyntaxHighlighting::State previousLineState;
|
||||||
|
if (TextBlockUserData *data = TextDocumentLayout::textUserData(previousBlock))
|
||||||
|
previousLineState = data->syntaxState();
|
||||||
|
KSyntaxHighlighting::State oldState;
|
||||||
if (TextBlockUserData *data = TextDocumentLayout::textUserData(block)) {
|
if (TextBlockUserData *data = TextDocumentLayout::textUserData(block)) {
|
||||||
state = data->syntaxState();
|
oldState = data->syntaxState();
|
||||||
data->setFoldingStartIncluded(false);
|
data->setFoldingStartIncluded(false);
|
||||||
data->setFoldingEndIncluded(false);
|
data->setFoldingEndIncluded(false);
|
||||||
}
|
}
|
||||||
state = highlightLine(text, state);
|
KSyntaxHighlighting::State state = highlightLine(text, previousLineState);
|
||||||
const QTextBlock nextBlock = block.next();
|
if (oldState != state) {
|
||||||
|
TextBlockUserData *data = TextDocumentLayout::userData(block);
|
||||||
|
data->setSyntaxState(state);
|
||||||
|
// Toggles the LSB of current block's userState. It forces rehighlight of next block.
|
||||||
|
setCurrentBlockState(currentBlockState() ^ 1);
|
||||||
|
}
|
||||||
|
|
||||||
Parentheses parentheses;
|
Parentheses parentheses;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@@ -300,13 +309,9 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
||||||
|
|
||||||
|
const QTextBlock nextBlock = block.next();
|
||||||
if (nextBlock.isValid()) {
|
if (nextBlock.isValid()) {
|
||||||
TextBlockUserData *data = TextDocumentLayout::userData(nextBlock);
|
TextBlockUserData *data = TextDocumentLayout::userData(nextBlock);
|
||||||
if (data->syntaxState() != state) {
|
|
||||||
data->setSyntaxState(state);
|
|
||||||
// Toggles the LSB of current block's userState. It forces rehighlight of next block.
|
|
||||||
setCurrentBlockState(currentBlockState() ^ 1);
|
|
||||||
}
|
|
||||||
data->setFoldingIndent(TextDocumentLayout::braceDepth(block));
|
data->setFoldingIndent(TextDocumentLayout::braceDepth(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user