diff --git a/src/Core/DataFilter.cpp b/src/Core/DataFilter.cpp index 9d24f2f479..e156277913 100644 --- a/src/Core/DataFilter.cpp +++ b/src/Core/DataFilter.cpp @@ -801,6 +801,7 @@ DataFilter::colorSyntax(QTextDocument *document, int pos) int symbolstart=0; int brace=0; int brack=0; + int sbrack=0; for(int i=0; i=0; j--) { + if (string[j]==']') bb++; + if (string[j]=='[') { + bb--; + if (bb == 0) { + bpos = j; // matched brack here, don't change color! + + cursor.setPosition(j, QTextCursor::MoveAnchor); + cursor.selectionStart(); + cursor.setPosition(j+1, QTextCursor::KeepAnchor); + cursor.selectionEnd(); + cursor.mergeCharFormat(cyanbg); + break; + } + } + } + + } else if (sbrack < 0 && i != bpos-1) { + + cursor.setPosition(i, QTextCursor::MoveAnchor); + cursor.selectionStart(); + cursor.setPosition(i+1, QTextCursor::KeepAnchor); + cursor.selectionEnd(); + cursor.mergeCharFormat(redbg); + } + } + // are the braces balanced ( ) ? if (!instring && !incomment && string[i]=='{') { brace++; @@ -1127,8 +1200,8 @@ DataFilter::colorSyntax(QTextDocument *document, int pos) brack = 0; for(int i=string.length(); i>=0; i--) { - if (string[i] == ')') brace++; - if (string[i] == '(') brace--; + if (string[i] == ')') brack++; + if (string[i] == '(') brack--; if (brack < 0 && string[i] == '(' && i != pos-1 && i != bpos-1) { cursor.setPosition(i, QTextCursor::MoveAnchor); @@ -1140,6 +1213,23 @@ DataFilter::colorSyntax(QTextDocument *document, int pos) } } + if (sbrack > 0) { + sbrack = 0; + for(int i=string.length(); i>=0; i--) { + + if (string[i] == ']') sbrack++; + if (string[i] == '[') sbrack--; + + if (sbrack < 0 && string[i] == '[' && i != pos-1 && i != bpos-1) { + cursor.setPosition(i, QTextCursor::MoveAnchor); + cursor.selectionStart(); + cursor.setPosition(i+1, QTextCursor::KeepAnchor); + cursor.selectionEnd(); + cursor.mergeCharFormat(redbg); + } + } + } + // apply selective coloring to the symbols and expressions if(treeRoot) treeRoot->color(treeRoot, document); }