ui: fixed multiple multiline comments within one line not correctly highlighted
This commit is contained in:
@@ -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())
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ Test Suites:\n\n
|
||||
[::\tmSINGLE_FILE_TESTS\ts\tp]\n
|
||||
[::\tmFILE_BAR_TESTS\ts\tp]\n
|
||||
[::\tmERROR_TESTS\ts\tp]\n
|
||||
[::\tmSYNTAX_HIGHLIGHTER_TESTS\ts\tp]\n
|
||||
</description>
|
||||
<source_groups>
|
||||
<source_group_475571d1-b082-4fff-81c5-d099c19f957d>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
namespace SYNTAX_HIGHLIGHTER_TESTS
|
||||
{
|
||||
|
||||
// TEST: multiline comments
|
||||
// START ----------------------------------------------------------------------
|
||||
|
||||
/**/
|
||||
|
||||
//*
|
||||
|
||||
///*
|
||||
|
||||
// /* /*
|
||||
|
||||
//* /*
|
||||
|
||||
/* comment */
|
||||
|
||||
/* comment *//* comment */
|
||||
|
||||
/* comment */ /* comment */
|
||||
|
||||
/* comment /* inside comment */
|
||||
|
||||
/* comment
|
||||
* comment
|
||||
* comment
|
||||
*/
|
||||
|
||||
/* start
|
||||
comment
|
||||
// end */
|
||||
|
||||
/* comment */ int no_comment; /* comment */
|
||||
|
||||
int no_comment2; /*
|
||||
* comment
|
||||
* comment
|
||||
*/ int no_comment3;
|
||||
|
||||
// /*
|
||||
int no_comment4;
|
||||
// */
|
||||
|
||||
//*
|
||||
int no_comment5;
|
||||
//*
|
||||
|
||||
const char no_commentStr1[] = " /* string */ "/* comment */;
|
||||
const char no_commentStr2[] = " /* "; /* comment */
|
||||
const char no_commentStr3[] = /* const char[] a = " no string */" this is a string "; // <- highlight broken
|
||||
|
||||
// RESULT: All no_comment variable are not highlighted as comment
|
||||
|
||||
// END ------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user