ui: fixed multiple multiline comments within one line not correctly highlighted

This commit is contained in:
Eberhard Graether
2018-12-05 00:20:46 +01:00
parent a044e17fdc
commit dc76661a53
3 changed files with 82 additions and 4 deletions
+23 -4
View File
@@ -270,7 +270,7 @@ void QtHighlighter::createRanges(
std::vector<std::pair<int, int>> QtHighlighter::createMultiLineCommentRanges(
QTextDocument* doc, std::vector<std::pair<int, int>>* ranges)
{
QRegExp commentStartExpression = QRegExp("(^([^/]|/[^/])*)/\\*");
QRegExp commentStartExpression = QRegExp("/\\*");
QRegExp commentEndExpression = QRegExp("\\*/");
QTextCursor cursorStart(doc);
@@ -280,15 +280,34 @@ std::vector<std::pair<int, int>> QtHighlighter::createMultiLineCommentRanges(
while (true)
{
do
while (true)
{
cursorStart = document()->find(commentStartExpression, cursorStart);
if (!cursorStart.isNull())
if (cursorStart.isNull())
{
break;
}
// ignore if within single line comment
QTextCursor inlineCommentStart = document()->find(s_commentRule.pattern, QTextCursor(cursorStart.block()));
if (!inlineCommentStart.isNull() &&
inlineCommentStart.blockNumber() == cursorStart.blockNumber() &&
inlineCommentStart.selectionStart() < cursorStart.selectionStart())
{
cursorStart = QTextCursor(inlineCommentStart.block().next());
continue;
}
if (!isInRange(cursorStart.selectionEnd(), *ranges))
{
cursorStart.setPosition(cursorStart.selectionEnd() - 2);
break;
}
else
{
cursorStart.setPosition(cursorStart.selectionEnd() + 2);
}
}
while (isInRange(cursorStart.selectionEnd(), *ranges));
if (cursorStart.isNull())
{