forked from qt-creator/qt-creator
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:
@@ -258,6 +258,16 @@ void Highlighter::handleShutdown()
|
|||||||
delete highlightRepository();
|
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)
|
void Highlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
if (!definition().isValid())
|
if (!definition().isValid())
|
||||||
@@ -266,6 +276,18 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
KSyntaxHighlighting::State state = TextDocumentLayout::userData(block)->syntaxState();
|
KSyntaxHighlighting::State state = TextDocumentLayout::userData(block)->syntaxState();
|
||||||
state = highlightLine(text, state);
|
state = highlightLine(text, state);
|
||||||
block = block.next();
|
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())
|
if (block.isValid())
|
||||||
TextDocumentLayout::userData(block)->setSyntaxState(state);
|
TextDocumentLayout::userData(block)->setSyntaxState(state);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user