diff --git a/bin/app/data/syntax_highlighting_rules/cpp.rules b/bin/app/data/syntax_highlighting_rules/cpp.rules index 65e2ec5f..51084dfc 100644 --- a/bin/app/data/syntax_highlighting_rules/cpp.rules +++ b/bin/app/data/syntax_highlighting_rules/cpp.rules @@ -1,7 +1,7 @@ [ { "type" : "quotation", - "patterns" : [ "\"([^\"]|\\\\.)*\"", "\'[^\']\'" ], + "patterns" : [ "\"(?:[^\"]|\\\\.)*\"", "\'[^\']\'" ], "priority" : true }, { diff --git a/bin/app/data/syntax_highlighting_rules/java.rules b/bin/app/data/syntax_highlighting_rules/java.rules index b38d71c8..d711584d 100644 --- a/bin/app/data/syntax_highlighting_rules/java.rules +++ b/bin/app/data/syntax_highlighting_rules/java.rules @@ -1,7 +1,7 @@ [ { "type" : "quotation", - "patterns" : [ "\"([^\"]|\\\\.)*\"", "\'[^\']\'" ], + "patterns" : [ "\"(?:[^\"]|\\\\.)*\"", "\'[^\']\'" ], "priority" : true }, { diff --git a/bin/app/data/syntax_highlighting_rules/python.rules b/bin/app/data/syntax_highlighting_rules/python.rules index 3677ab62..e118d28c 100644 --- a/bin/app/data/syntax_highlighting_rules/python.rules +++ b/bin/app/data/syntax_highlighting_rules/python.rules @@ -17,7 +17,7 @@ }, { "type" : "quotation", - "patterns" : [ "\"([^\"]|\\\\.)+\"", "\"\"[^\"]", "[^\"]\"\"$", "\'([^\']|\\\\.)+\'", "\'\'[^\']", "[^\']\'\'$" ], + "patterns" : [ "(?:[^\"]|^)(\"(?:[^\"]|\\\\.)*\")(?:[^\"]|$)", "(?:[^\']|^)(\'(?:[^\']|\\\\.)*\')(?:[^\']|$)" ], "priority" : true }, { diff --git a/src/lib_gui/qt/utility/QtHighlighter.cpp b/src/lib_gui/qt/utility/QtHighlighter.cpp index b704b72a..3438c742 100644 --- a/src/lib_gui/qt/utility/QtHighlighter.cpp +++ b/src/lib_gui/qt/utility/QtHighlighter.cpp @@ -446,18 +446,26 @@ bool QtHighlighter::isInRange(int pos, const std::vector> QtHighlighter::getRangesForRule( const QTextBlock& block, const HighlightingRule& rule) const { + const int pos = block.position(); + const QString text = block.text(); QRegExp expression(rule.pattern); - int pos = block.position(); - int index = expression.indexIn(block.text()); + int index = expression.indexIn(text); std::vector> ranges; while (index >= 0) { - int length = expression.matchedLength(); - - ranges.push_back(std::make_tuple(rule.type, pos + index, pos + index + length)); - + const int length = expression.matchedLength(); + if (expression.capturedTexts().size() > 1) + { + const QString cap = expression.capturedTexts()[1]; + const int start = text.indexOf(cap, index); + ranges.push_back(std::make_tuple(rule.type, pos + start, pos + start + cap.length())); + } + else + { + ranges.push_back(std::make_tuple(rule.type, pos + index, pos + index + length)); + } index = expression.indexIn(block.text(), index + length); }