forked from qt-creator/qt-creator
TextEditor: Highlight and animate matching parenthesis for generic highlighter
Change-Id: I78db37a91f1770513fcb5192bf45623799e14e34 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
committed by
David Schulz
parent
a0715512ca
commit
8276253558
@@ -155,6 +155,16 @@ void Highlighter::setTabSettings(const TabSettings &ts)
|
||||
m_tabSettings = &ts;
|
||||
}
|
||||
|
||||
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 (!m_defaultContext.isNull() && !m_isBroken) {
|
||||
@@ -184,6 +194,17 @@ void Highlighter::highlightBlock(const QString &text)
|
||||
// In the case region depth has changed since the last time the state was set.
|
||||
setCurrentBlockState(computeState(extractObservableState(currentBlockState())));
|
||||
}
|
||||
|
||||
TextEditor::Parentheses parentheses;
|
||||
for (int pos = 0; pos < length; ++pos) {
|
||||
const QChar c = text.at(pos);
|
||||
if (isOpeningParenthesis(c))
|
||||
parentheses.push_back(Parenthesis(Parenthesis::Opened, c, pos));
|
||||
else if (isClosingParenthesis(c))
|
||||
parentheses.push_back(Parenthesis(Parenthesis::Closed, c, pos));
|
||||
}
|
||||
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
||||
|
||||
} catch (const HighlighterException &) {
|
||||
m_isBroken = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user