diff options
author | David Schulz <david.schulz@qt.io> | 2019-06-05 09:26:12 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-06-07 05:20:36 +0000 |
commit | 6fd355b84b48682012c3914d264848084fe7b230 (patch) | |
tree | 398e30e87df33dfa342fe98a7a95d16c5b8bd77c /src | |
parent | 6178e871da150c0791c819ecb85a7ed245867eef (diff) | |
download | qt-creator-6fd355b84b48682012c3914d264848084fe7b230.tar.gz |
TextEditor: force rehighlight of next block if state changed
If the user state of a block changes while it gets highlighted
the next block will be rehighlighted too. Currently we store the
indentation depth in the block user state. So in order to store the
indentation depth _and_ the information whether the next block needs
to be rehighlighted we bit shift the indentation depth via the
brace depth helper functions from TextDocumentLayaout. And we cannot
store the struct KSyntaxHighlighting::State in the block user state (int)
directly to indicate that the next block also needs a rehighlight so we
toggle just the last bit of the user state.
Fixes: QTCREATORBUG-22290
Change-Id: I632f4416a725dc5fa1667bcab34fb2701294c9b8
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/texteditor/highlighter.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/plugins/texteditor/highlighter.cpp b/src/plugins/texteditor/highlighter.cpp index 07ec2fcf96..ee958795ae 100644 --- a/src/plugins/texteditor/highlighter.cpp +++ b/src/plugins/texteditor/highlighter.cpp @@ -274,9 +274,9 @@ void Highlighter::highlightBlock(const QString &text) { if (!definition().isValid()) return; - const QTextBlock block = currentBlock(); + QTextBlock block = currentBlock(); KSyntaxHighlighting::State state; - setCurrentBlockState(qMax(0, previousBlockState())); + TextDocumentLayout::setBraceDepth(block, TextDocumentLayout::braceDepth(block.previous())); if (TextBlockUserData *data = TextDocumentLayout::testUserData(block)) { state = data->syntaxState(); data->setFoldingStartIncluded(false); @@ -298,8 +298,11 @@ void Highlighter::highlightBlock(const QString &text) if (nextBlock.isValid()) { TextBlockUserData *data = TextDocumentLayout::userData(nextBlock); - data->setSyntaxState(state); - data->setFoldingIndent(currentBlockState()); + if (data->syntaxState() != state) { + data->setSyntaxState(state); + setCurrentBlockState(currentBlockState() ^ 1); // force rehighlight of next block + } + data->setFoldingIndent(TextDocumentLayout::braceDepth(block)); } formatSpaces(text); @@ -316,24 +319,24 @@ void Highlighter::applyFolding(int offset, { if (!region.isValid()) return; - const QTextBlock &block = currentBlock(); + QTextBlock block = currentBlock(); const QString &text = block.text(); TextBlockUserData *data = TextDocumentLayout::userData(currentBlock()); const bool fromStart = TabSettings::firstNonSpace(text) == offset; const bool toEnd = (offset + length) == (text.length() - TabSettings::trailingWhitespaces(text)); if (region.type() == KSyntaxHighlighting::FoldingRegion::Begin) { - setCurrentBlockState(currentBlockState() + 1); + TextDocumentLayout::changeBraceDepth(block, 1); // if there is only a folding begin in the line move the current block into the fold if (fromStart && toEnd) { - data->setFoldingIndent(currentBlockState()); + data->setFoldingIndent(TextDocumentLayout::braceDepth(block)); data->setFoldingStartIncluded(true); } } else if (region.type() == KSyntaxHighlighting::FoldingRegion::End) { - setCurrentBlockState(qMax(0, currentBlockState() - 1)); + TextDocumentLayout::changeBraceDepth(block, -1); // if the folding end is at the end of the line move the current block into the fold if (toEnd) data->setFoldingEndIncluded(true); else - data->setFoldingIndent(currentBlockState()); + data->setFoldingIndent(TextDocumentLayout::braceDepth(block)); } } |