Commit efe316f8 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppTools: Define '<' and '>' as electrical characters



Required for auto-indenting stream operations. For example:

std::cout << foo
          << bar;

without explicitly invoking the indenter.

Change-Id: I3a88083af5295709dfecb384538078e236119b0b
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 152f9c36
......@@ -58,30 +58,39 @@ bool CppQtStyleIndenter::isElectricCharacter(const QChar &ch) const
case '}':
case ':':
case '#':
case '<':
case '>':
return true;
}
return false;
}
static bool colonIsElectric(const QString &text)
static bool isElectricInLine(const QChar ch, const QString &text)
{
// switch cases and access declarations should be reindented
if (text.contains(QLatin1String("case"))
|| text.contains(QLatin1String("default"))
|| text.contains(QLatin1String("public"))
|| text.contains(QLatin1String("private"))
|| text.contains(QLatin1String("protected"))
|| text.contains(QLatin1String("signals"))
|| text.contains(QLatin1String("Q_SIGNALS"))) {
return true;
switch (ch.toLatin1()) {
case ':':
// switch cases and access declarations should be reindented
if (text.contains(QLatin1String("case"))
|| text.contains(QLatin1String("default"))
|| text.contains(QLatin1String("public"))
|| text.contains(QLatin1String("private"))
|| text.contains(QLatin1String("protected"))
|| text.contains(QLatin1String("signals"))
|| text.contains(QLatin1String("Q_SIGNALS"))) {
return true;
}
// fall-through
// lines that start with : might have a constructor initializer list
case '<':
case '>': {
// Electrical if at line beginning (after space indentation)
const QString trimmedtext = text.trimmed();
return !trimmedtext.isEmpty() && trimmedtext.at(0) == ch;
}
}
// lines that start with : might have a constructor initializer list
const QString trimmedtext = text.trimmed();
if (!trimmedtext.isEmpty() && trimmedtext.at(0) == QLatin1Char(':'))
return true;
return false;
return true;
}
void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
......@@ -100,7 +109,7 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
if (isElectricCharacter(typedChar)) {
// : should not be electric for labels
if (typedChar == QLatin1Char(':') && !colonIsElectric(block.text()))
if (!isElectricInLine(typedChar, block.text()))
return;
// only reindent the current line when typing electric characters if the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment