From e3e4f1b986d82f313d676d38f3526baaee120e6a Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Wed, 13 Jan 2010 14:25:52 +0100 Subject: [PATCH] Improved the QML/JS indenter when indenting statements with inserted semicolons --- .../qscripthighlighter/qscriptindenter.cpp | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/shared/qscripthighlighter/qscriptindenter.cpp b/src/shared/qscripthighlighter/qscriptindenter.cpp index 4f8d5ab9e6c..dd639e03754 100644 --- a/src/shared/qscripthighlighter/qscriptindenter.cpp +++ b/src/shared/qscripthighlighter/qscriptindenter.cpp @@ -272,21 +272,36 @@ QString QScriptIndenter::trimmedCodeLine(const QString &t) const /* Remove C++-style comments. */ - k = trimmed.indexOf(QLatin1String("//")); + k = trimmed.indexOf(QRegExp(QLatin1String("\\s*//"))); if (k != -1) trimmed.truncate(k); - const QString e = trimmed.trimmed(); - - if (insertSemicolon || e.endsWith(QLatin1Char(',')) || e.endsWith(QLatin1Char(']'))) - trimmed.append(QLatin1Char(';')); - else if (trimmed.indexOf(propertylikeKeyword) != -1) { + if (! insertSemicolon && ! trimmed.isEmpty()) { const QChar ch = trimmed.at(trimmed.length() - 1); - if (ch.isLetterOrNumber() || ch == QLatin1Char(')') || ch == QLatin1Char(']') - || ch == QLatin1Char('"') || ch == QLatin1Char('\'')) - trimmed.append(QLatin1Char(';')); + + switch (ch.unicode()) { + case ',': + case ']': + case '"': + case '\'': + case '_': + insertSemicolon = true; + break; + + default: + if (ch.isLetterOrNumber()) { + if (! trimmed.endsWith(QLatin1String("else"))) + insertSemicolon = true; + } else if (trimmed.indexOf(propertylikeKeyword) != -1) + insertSemicolon = true; + + break; + } } + if (insertSemicolon) + trimmed.append(QLatin1Char(';')); + return trimmed; } -- GitLab