aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/syntaxhighlighter.cpp
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2024-02-23 17:37:03 +0100
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2024-02-28 11:53:02 +0000
commit95a5f010962ab642a3dbd9d6f8f96f3b2e917b79 (patch)
tree58ff7479b932d891180148d73f01e760d5665787 /src/plugins/texteditor/syntaxhighlighter.cpp
parent3f785928319716c76cc4eb23eebb0dc8c60a7429 (diff)
TextEditor: Fix folding for async syntax highlighter
- Made restoreState, ensureBlockIsUnfolded, fold, unfold and unfoldAll functions to be called only after highlighting is done - Improved management of foldValidator in async case - Removed optimizations in cpphighlighter and glshighlighter. The highlighters are async now and optimization is not necessary. In these optimizations in the function highlightBlock the highlighting changes not only for currentBlock but and for several next. Which is contradict with the function name. Change-Id: Ib413e6b982eb39d52f36c3066ff0fa8c28fbe231 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index 0ed00af389..34f4b1c777 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -81,6 +81,10 @@ void SyntaxHighlighter::delayedRehighlight()
if (!d->rehighlightPending)
return;
d->rehighlightPending = false;
+
+ if (document()->isEmpty())
+ return;
+
rehighlight();
}
@@ -197,6 +201,10 @@ void SyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int ch
QList<SyntaxHighlighter::Result> vecRes;
+ SyntaxHighlighter::Result resStart;
+ resStart.m_state = SyntaxHighlighter::State::Start;
+ vecRes << resStart;
+
while (block.isValid() && (block.position() < endPosition || forceHighlightOfNextBlock)) {
if (QThread::currentThread()->isInterruptionRequested())
break;
@@ -758,7 +766,10 @@ void SyntaxHighlighter::setExtraFormats(const QTextBlock &block,
SyntaxHighlighter::Result res;
res.m_formatRanges = block.layout()->formats();
res.fillByBlock(block);
- emit resultsReady({res});
+ res.m_state = SyntaxHighlighter::State::Extras;
+ SyntaxHighlighter::Result resDone;
+ resDone.m_state = SyntaxHighlighter::State::Done;
+ emit resultsReady({res, resDone});
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;
@@ -784,7 +795,10 @@ void SyntaxHighlighter::clearExtraFormats(const QTextBlock &block)
SyntaxHighlighter::Result res;
res.m_formatRanges = block.layout()->formats();
res.fillByBlock(block);
- emit resultsReady({res});
+ res.m_state = SyntaxHighlighter::State::Extras;
+ SyntaxHighlighter::Result resDone;
+ resDone.m_state = SyntaxHighlighter::State::Done;
+ emit resultsReady({res, resDone});
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;