Commit a38c6f30 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Fix performance issue in Code Editor (very slow)

parent 87fbbfa8
......@@ -18,42 +18,45 @@ QmlSyntaxTokenId::QmlSyntaxTokenId (const int position, const QString & identifi
QmlSyntaxHighlighter::QmlSyntaxHighlighter (QTextDocument * document)
: QSyntaxHighlighter (document)
, m_useDarkTheme (true)
, keywords ({
"if",
"else",
"return",
"import",
"signal",
"property",
"function",
"readonly",
"alias",
"for",
"in",
"do",
"while",
"break",
"continue",
"switch",
"case",
"default",
"var",
"null",
"undefined",
"string",
"bool",
"int",
"real",
"date",
"true",
"false",
})
, highlightingRules ({
Rule { "\\b[a-z][a-zA-Z0-9_]*\\b", &memberFormat }, // member
Rule { "\\b[0-9]+\\b", &numberFormat }, // numbers
Rule { "\\b0x[0-9A-Fa-f]+\\b", &numberFormat }, // hexa
Rule { "\\bif\\b", &keywordFormat },
Rule { "\\belse\\b", &keywordFormat },
Rule { "\\breturn\\b", &keywordFormat },
Rule { "\\bimport\\b", &keywordFormat },
Rule { "\\bsignal\\b", &keywordFormat },
Rule { "\\bproperty\\b", &keywordFormat },
Rule { "\\bfunction\\b", &keywordFormat },
Rule { "\\breadonly\\b", &keywordFormat },
Rule { "\\balias\\b", &keywordFormat },
Rule { "\\bfor\\b", &keywordFormat },
Rule { "\\bin\\b", &keywordFormat },
Rule { "\\bdo\\b", &keywordFormat },
Rule { "\\bwhile\\b", &keywordFormat },
Rule { "\\bbreak\\b", &keywordFormat },
Rule { "\\bcontinue\\b", &keywordFormat },
Rule { "\\bswitch\\b", &keywordFormat },
Rule { "\\bcase\\b", &keywordFormat },
Rule { "\\bdefault\\b", &keywordFormat },
Rule { "\\bvar\\b", &keywordFormat },
Rule { "\\bnull\\b", &keywordFormat },
Rule { "\\bundefined\\b", &keywordFormat },
Rule { "\\bstring\\b", &keywordFormat },
Rule { "\\bbool\\b", &keywordFormat },
Rule { "\\bint\\b", &keywordFormat },
Rule { "\\breal\\b", &keywordFormat },
Rule { "\\bdate\\b", &keywordFormat },
Rule { "\\btrue\\b", &keywordFormat },
Rule { "\\bfalse\\b", &keywordFormat },
Rule { "\\b[A-Z][a-zA-Z0-9_]*\\b", &objectFormat }, // objects
Rule { "\".*\"", &quotationFormat }, // double quoted string
Rule { "'.*'", &quotationFormat }, // simple quoted string
Rule { "\\/\\/.*", &commentFormat }, // double slash comment
Rule { "\\b[a-z][a-zA-Z0-9_]*\\b", &memberFormat }, // member
Rule { "\\b[0-9]+\\b", &numberFormat }, // numbers
Rule { "\\b0x[0-9A-Fa-f]+\\b", &numberFormat }, // hexa
Rule { ("\\b(" % keywords.join ('|') % ")\\b"), &keywordFormat }, // keywords
Rule { "\\b[A-Z][a-zA-Z0-9_]*\\b", &objectFormat }, // objects
Rule { "\".*\"", &quotationFormat }, // double quoted string
Rule { "'.*'", &quotationFormat }, // simple quoted string
Rule { "\\/\\/.*", &commentFormat }, // double slash comment
})
, highlightingRulesMultiline ({
RuleMultiline { "/\\*", "\\*/", &commentFormat, Commented }, // block comment
......@@ -119,7 +122,10 @@ SyntaxHighlighter::SyntaxHighlighter (QObject * parent)
m_inhibitReparse = new QTimer (this);
m_inhibitReparse->setInterval (2000);
m_inhibitReparse->setSingleShot (true);
connect (m_inhibitReparse, &QTimer::timeout, this, &SyntaxHighlighter::refreshAst);
connect (m_inhibitReparse, &QTimer::timeout, [this] () {
refreshAst ();
emit infoChanged (m_info);
});
}
QVariantList SyntaxHighlighter::getAutoCompletionAtPos (const int position) {
......@@ -155,9 +161,10 @@ void SyntaxHighlighter::componentComplete (void) {
connect (this, &SyntaxHighlighter::useDarkThemeChanged, highlighter, &QmlSyntaxHighlighter::update_useDarkTheme);
connect (doc, &QTextDocument::contentsChanged, [this] () {
m_dirty = true;
m_inhibitReparse->stop ();
if (m_inhibitReparse->isActive ()) {
m_inhibitReparse->stop ();
}
m_inhibitReparse->start ();
emit infoChanged (m_info);
});
}
}
......
......@@ -65,8 +65,9 @@ private:
QTextCharFormat * format;
BlockStates state;
};
QVector<Rule> highlightingRules;
QVector<RuleMultiline> highlightingRulesMultiline;
const QStringList keywords;
const QVector<Rule> highlightingRules;
const QVector<RuleMultiline> highlightingRulesMultiline;
};
class DocInfo : public QObject {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment