summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/syntaxhighlighter.cpp
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-07-18 17:37:08 +0200
committerMarco Bubke <marco.bubke@qt.io>2017-07-19 09:25:40 +0000
commitb9b69bac339adad49bfc0cac94159b87697c94c7 (patch)
treed9726ec6e9c1c144abef948d2ded4b730d6f440e /src/plugins/texteditor/syntaxhighlighter.cpp
parent19cdb75a8af50ac8f1dc8c5c095b63f5b6c87f04 (diff)
downloadqt-creator-b9b69bac339adad49bfc0cac94159b87697c94c7.tar.gz
TextEditor: Disconnect highlighting from text editor content changes
The syntax highligher is connected to the content changes of the text editor which is not very useful if the diagnostics been provided by an asynchronous mechanism. So we add a setter to disconnect the changes from the syntax highlighter. Change-Id: Ied4b5fe34000b13bafb1aa177b89befe6620d4d7 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/syntaxhighlighter.cpp')
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index ebe2d9aaeb..13bc6bba30 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -43,11 +43,10 @@ namespace TextEditor {
class SyntaxHighlighterPrivate
{
- SyntaxHighlighter *q_ptr;
+ SyntaxHighlighter *q_ptr = nullptr;
Q_DECLARE_PUBLIC(SyntaxHighlighter)
public:
- inline SyntaxHighlighterPrivate()
- : q_ptr(0), rehighlightPending(false), inReformatBlocks(false)
+ SyntaxHighlighterPrivate()
{
updateFormats(TextEditorSettings::fontSettings());
}
@@ -70,12 +69,13 @@ public:
QVector<QTextCharFormat> formatChanges;
QTextBlock currentBlock;
- bool rehighlightPending;
- bool inReformatBlocks;
+ bool rehighlightPending = false;
+ bool inReformatBlocks = false;
TextDocumentLayout::FoldValidator foldValidator;
QVector<QTextCharFormat> formats;
QVector<std::pair<int,TextStyle>> formatCategories;
QTextCharFormat whitespaceFormat;
+ bool noAutomaticHighlighting = false;
};
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsRemoved, int charsAdded) {
@@ -315,9 +315,11 @@ void SyntaxHighlighter::setDocument(QTextDocument *doc)
}
d->doc = doc;
if (d->doc) {
- connect(d->doc, &QTextDocument::contentsChange, this, &SyntaxHighlighter::reformatBlocks);
- d->rehighlightPending = true;
- QTimer::singleShot(0, this, &SyntaxHighlighter::delayedRehighlight);
+ if (!d->noAutomaticHighlighting) {
+ connect(d->doc, &QTextDocument::contentsChange, this, &SyntaxHighlighter::reformatBlocks);
+ d->rehighlightPending = true;
+ QTimer::singleShot(0, this, &SyntaxHighlighter::delayedRehighlight);
+ }
d->foldValidator.setup(qobject_cast<TextDocumentLayout *>(doc->documentLayout()));
}
}
@@ -764,6 +766,15 @@ void SyntaxHighlighter::setFontSettings(const FontSettings &fontSettings)
Q_D(SyntaxHighlighter);
d->updateFormats(fontSettings);
}
+/*!
+ The syntax highlighter is not anymore reacting to the text document if \a noAutmatic is
+ \c true.
+*/
+void SyntaxHighlighter::setNoAutomaticHighlighting(bool noAutomatic)
+{
+ Q_D(SyntaxHighlighter);
+ d->noAutomaticHighlighting = noAutomatic;
+}
/*!
Creates text format categories for the text styles themselves, so the highlighter can