TextEditor: Fix matching parenthesis highlight reggression

The update to the new KSyntaxHighlight engine was missing the matching
parenthesis highlight that was implemented in the generic highligter.

Fixes: QTCREATORBUG-22095
Change-Id: Ibac0f0739b4e1df63aadf0f18f1b76873e63a2fc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2019-03-07 10:03:09 +01:00
parent 15a0f9d14b
commit 792fe95c00

View File

@@ -258,6 +258,16 @@ void Highlighter::handleShutdown()
delete highlightRepository();
}
static bool isOpeningParenthesis(QChar c)
{
return c == QLatin1Char('{') || c == QLatin1Char('[') || c == QLatin1Char('(');
}
static bool isClosingParenthesis(QChar c)
{
return c == QLatin1Char('}') || c == QLatin1Char(']') || c == QLatin1Char(')');
}
void Highlighter::highlightBlock(const QString &text)
{
if (!definition().isValid())
@@ -266,6 +276,18 @@ void Highlighter::highlightBlock(const QString &text)
KSyntaxHighlighting::State state = TextDocumentLayout::userData(block)->syntaxState();
state = highlightLine(text, state);
block = block.next();
Parentheses parentheses;
int pos = 0;
for (const QChar &c : text) {
if (isOpeningParenthesis(c))
parentheses.push_back(Parenthesis(Parenthesis::Opened, c, pos));
else if (isClosingParenthesis(c))
parentheses.push_back(Parenthesis(Parenthesis::Closed, c, pos));
pos++;
}
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
if (block.isValid())
TextDocumentLayout::userData(block)->setSyntaxState(state);
}