History

- Highlighting Fixes ( Single line comments in quoted text don't occur anymore. / Better number recognition) - Line numbers in ScriptEditor

Thijs Wenker committed 12 years ago

Commit cf1baaf1 parent 7125b6a8 files · +240 −8Browse files

Showing the changes to interface/src/ScriptHighlighting.cpp (1 of 8 files). Show all

Unified · Split

interface/src/ScriptHighlighting.cpp+17−2
@@ -22,6 +22,7 @@ ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) : · 21 unmodified lines
2222 _numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}");
2323 _singleLineComment = QRegExp("//[^\n]*");
2424 _truefalseRegex = QRegExp("\\b(true|false)\\b");
25+ _alphacharRegex = QRegExp("[A-Za-z]");
2526 }
2627
2728 void ScriptHighlighting::highlightBlock(const QString& text) {
@@ -60,7 +61,19 @@ void ScriptHighlighting::formatComments(const QString& text) { · 32 unmodified lines
6061 int index = _singleLineComment.indexIn(text);
6162 while (index >= 0) {
6263 int length = _singleLineComment.matchedLength();
63− setFormat(index, length, Qt::lightGray);
64+ int quoted_index = _qoutedTextRegex.indexIn(text);
65+ bool valid = true;
66+ while (quoted_index >= 0 && valid) {
67+ int quoted_length = _qoutedTextRegex.matchedLength();
68+ if (quoted_index <= index && index <= (quoted_index + quoted_length)) {
69+ valid = false;
70+ }
71+ quoted_index = _qoutedTextRegex.indexIn(text, quoted_index + quoted_length);
72+ }
73+
74+ if (valid) {
75+ setFormat(index, length, Qt::lightGray);
76+ }
6477 index = _singleLineComment.indexIn(text, index + length);
6578 }
6679 }
@@ -78,7 +91,9 @@ void ScriptHighlighting::formatNumbers(const QString& text){ · 11 unmodified lines
7891 int index = _numberRegex.indexIn(text);
7992 while (index >= 0) {
8093 int length = _numberRegex.matchedLength();
81− setFormat(index, length, Qt::green);
94+ if (index == 0 || _alphacharRegex.indexIn(text, index - 1) != (index - 1)) {
95+ setFormat(index, length, Qt::green);
96+ }
8297 index = _numberRegex.indexIn(text, index + length);
8398 }
8499 }