Update jsedit.cpp
Highlight custom objects, callback functions and functions with a custom flashy color
This commit is contained in:
+33
-2
@@ -54,6 +54,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QSet<QString> m_keywords;
|
QSet<QString> m_keywords;
|
||||||
QSet<QString> m_knownIds;
|
QSet<QString> m_knownIds;
|
||||||
|
QSet<QString> m_customIds;
|
||||||
QHash<JSEdit::ColorComponent, QColor> m_colors;
|
QHash<JSEdit::ColorComponent, QColor> m_colors;
|
||||||
QString m_markString;
|
QString m_markString;
|
||||||
Qt::CaseSensitivity m_markCaseSensitivity;
|
Qt::CaseSensitivity m_markCaseSensitivity;
|
||||||
@@ -73,6 +74,7 @@ JSHighlighter::JSHighlighter(QTextDocument *parent)
|
|||||||
m_colors[JSEdit::Keyword] = QColor("#000080");
|
m_colors[JSEdit::Keyword] = QColor("#000080");
|
||||||
m_colors[JSEdit::BuiltIn] = QColor("#008080");
|
m_colors[JSEdit::BuiltIn] = QColor("#008080");
|
||||||
m_colors[JSEdit::Marker] = QColor("#ffff00");
|
m_colors[JSEdit::Marker] = QColor("#ffff00");
|
||||||
|
m_colors[JSEdit::Custom] = QColor("#ff00ff");
|
||||||
|
|
||||||
// https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
|
// https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
|
||||||
m_keywords << "break";
|
m_keywords << "break";
|
||||||
@@ -248,6 +250,27 @@ JSHighlighter::JSHighlighter(QTextDocument *parent)
|
|||||||
m_knownIds << "window";
|
m_knownIds << "window";
|
||||||
m_knownIds << "navigator";
|
m_knownIds << "navigator";
|
||||||
m_knownIds << "userAgent";
|
m_knownIds << "userAgent";
|
||||||
|
|
||||||
|
//Custom objects
|
||||||
|
m_customIds << "host";
|
||||||
|
m_customIds << "can";
|
||||||
|
m_customIds << "isotp";
|
||||||
|
m_customIds << "uds";
|
||||||
|
//Custom callback functions
|
||||||
|
m_customIds << "setup";
|
||||||
|
m_customIds << "tick";
|
||||||
|
m_customIds << "gotCANFrame";
|
||||||
|
m_customIds << "gotISOTPMessage";
|
||||||
|
m_customIds << "gotUDSMessage";
|
||||||
|
//Custom functions
|
||||||
|
m_customIds << "setTickInterval";
|
||||||
|
m_customIds << "log"; //Duplicate
|
||||||
|
m_customIds << "addParameter";
|
||||||
|
m_customIds << "setFilter";
|
||||||
|
m_customIds << "clearFilters";
|
||||||
|
m_customIds << "sendFrame";
|
||||||
|
m_customIds << "sendISOTP";
|
||||||
|
m_customIds << "sendUDS";
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSHighlighter::setColor(JSEdit::ColorComponent component, const QColor &color)
|
void JSHighlighter::setColor(JSEdit::ColorComponent component, const QColor &color)
|
||||||
@@ -269,6 +292,7 @@ void JSHighlighter::highlightBlock(const QString &text)
|
|||||||
};
|
};
|
||||||
|
|
||||||
QList<int> bracketPositions;
|
QList<int> bracketPositions;
|
||||||
|
QString previousToken;
|
||||||
|
|
||||||
int blockState = previousBlockState();
|
int blockState = previousBlockState();
|
||||||
int bracketLevel = blockState >> 4;
|
int bracketLevel = blockState >> 4;
|
||||||
@@ -336,10 +360,17 @@ void JSHighlighter::highlightBlock(const QString &text)
|
|||||||
case Identifier:
|
case Identifier:
|
||||||
if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) {
|
if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) {
|
||||||
QString token = text.mid(start, i - start).trimmed();
|
QString token = text.mid(start, i - start).trimmed();
|
||||||
if (m_keywords.contains(token))
|
if (m_customIds.contains(token) && m_customIds.contains(previousToken)) {
|
||||||
|
setFormat(start, i - start, m_colors[JSEdit::Custom]);
|
||||||
|
} else if (m_keywords.contains(token)) {
|
||||||
setFormat(start, i - start, m_colors[JSEdit::Keyword]);
|
setFormat(start, i - start, m_colors[JSEdit::Keyword]);
|
||||||
else if (m_knownIds.contains(token))
|
} else if (m_knownIds.contains(token)) {
|
||||||
setFormat(start, i - start, m_colors[JSEdit::BuiltIn]);
|
setFormat(start, i - start, m_colors[JSEdit::BuiltIn]);
|
||||||
|
if (ch == '.') previousToken = token;
|
||||||
|
} else if (m_customIds.contains(token)) {
|
||||||
|
setFormat(start, i - start, m_colors[JSEdit::Custom]);
|
||||||
|
if (ch == '.') previousToken = token;
|
||||||
|
}
|
||||||
state = Start;
|
state = Start;
|
||||||
} else {
|
} else {
|
||||||
++i;
|
++i;
|
||||||
|
|||||||
Reference in New Issue
Block a user