diff options
author | Artem Sokolovskii <artem.sokolovskii@qt.io> | 2024-02-23 17:37:03 +0100 |
---|---|---|
committer | Artem Sokolovskii <artem.sokolovskii@qt.io> | 2024-02-28 11:53:02 +0000 |
commit | 95a5f010962ab642a3dbd9d6f8f96f3b2e917b79 (patch) | |
tree | 58ff7479b932d891180148d73f01e760d5665787 /src/plugins/cppeditor | |
parent | 3f785928319716c76cc4eb23eebb0dc8c60a7429 (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/cppeditor')
-rw-r--r-- | src/plugins/cppeditor/cpphighlighter.cpp | 21 | ||||
-rw-r--r-- | src/plugins/cppeditor/cpptoolstestcase.cpp | 14 |
2 files changed, 13 insertions, 22 deletions
diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index 591881c6c5..becebd1188 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -242,27 +242,6 @@ void CppHighlighter::highlightBlock(const QString &text) TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent); - // optimization: if only the brace depth changes, we adjust subsequent blocks - // to have QSyntaxHighlighter stop the rehighlighting - int currentState = currentBlockState(); - if (currentState != -1) { - int oldState = currentState & 0xff; - int oldBraceDepth = currentState >> 8; - if (oldState == tokenize.state() && oldBraceDepth != braceDepth) { - TextDocumentLayout::FoldValidator foldValidor; - foldValidor.setup(qobject_cast<TextDocumentLayout *>(document()->documentLayout())); - int delta = braceDepth - oldBraceDepth; - QTextBlock block = currentBlock().next(); - while (block.isValid() && block.userState() != -1) { - TextDocumentLayout::changeBraceDepth(block, delta); - TextDocumentLayout::changeFoldingIndent(block, delta); - foldValidor.process(block); - block = block.next(); - } - foldValidor.finalize(); - } - } - setCurrentBlockState((braceDepth << 8) | tokenize.state()); TextDocumentLayout::setExpectedRawStringSuffix(currentBlock(), tokenize.expectedRawStringSuffix()); diff --git a/src/plugins/cppeditor/cpptoolstestcase.cpp b/src/plugins/cppeditor/cpptoolstestcase.cpp index 37b5d855d0..a55895affc 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.cpp +++ b/src/plugins/cppeditor/cpptoolstestcase.cpp @@ -20,10 +20,11 @@ #include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectmanager.h> -#include <texteditor/texteditor.h> #include <texteditor/codeassist/iassistproposal.h> #include <texteditor/codeassist/iassistproposalmodel.h> #include <texteditor/storagesettings.h> +#include <texteditor/syntaxhighlighterrunner.h> +#include <texteditor/texteditor.h> #include <utils/environment.h> #include <utils/fileutils.h> @@ -221,6 +222,17 @@ bool TestCase::openCppEditor(const FilePath &filePath, TextEditor::BaseTextEdito s.m_addFinalNewLine = false; e->textDocument()->setStorageSettings(s); } + + if (!QTest::qWaitFor( + [e] { + return e->editorWidget() + ->textDocument() + ->syntaxHighlighterRunner() + ->syntaxInfoUpdated(); + }, + 5000)) + return false; + if (editorWidget) { if (CppEditorWidget *w = dynamic_cast<CppEditorWidget *>(e->editorWidget())) { *editorWidget = w; |