forked from qt-creator/qt-creator
Editor: Fix whitespace cleaning.
Task-number: QTCREATORBUG-7994 Change-Id: I6c197ccc3a148555018e8f8184d116c88d7ea400 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -48,40 +48,36 @@ bool JavaIndenter::isElectricCharacter(const QChar &ch) const
|
||||
}
|
||||
|
||||
void JavaIndenter::indentBlock(QTextDocument *doc,
|
||||
const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
// At beginning: Leave as is.
|
||||
if (block == doc->begin())
|
||||
return;
|
||||
|
||||
const int tabsize = tabSettings.m_indentSize;
|
||||
Q_UNUSED(doc);
|
||||
int indent = indentFor(block, tabSettings);
|
||||
if (typedChar == QLatin1Char('}'))
|
||||
indent -= tabSettings.m_indentSize;
|
||||
tabSettings.indentLine(block, qMax(0, indent));
|
||||
}
|
||||
|
||||
int JavaIndenter::indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
{
|
||||
QTextBlock previous = block.previous();
|
||||
if (!previous.isValid())
|
||||
return 0;
|
||||
|
||||
QString previousText = previous.text();
|
||||
while (previousText.trimmed().isEmpty()) {
|
||||
previous = previous.previous();
|
||||
if (previous == doc->begin())
|
||||
return;
|
||||
if (!previous.isValid())
|
||||
return 0;
|
||||
previousText = previous.text();
|
||||
}
|
||||
|
||||
int adjust = 0;
|
||||
if (previousText.contains(QLatin1Char('{')))
|
||||
adjust = tabsize;
|
||||
int indent = tabSettings.indentationColumn(previousText);
|
||||
|
||||
if (block.text().contains(QLatin1Char('}')) || typedChar == QLatin1Char('}'))
|
||||
adjust += -tabsize;
|
||||
int adjust = previousText.count(QLatin1Char('{')) - previousText.count(QLatin1Char('}'));
|
||||
adjust *= tabSettings.m_indentSize;
|
||||
|
||||
// Count the indentation of the previous line.
|
||||
int i = 0;
|
||||
while (i < previousText.size()) {
|
||||
if (!previousText.at(i).isSpace()) {
|
||||
tabSettings.indentLine(block, tabSettings.columnAt(previousText, i)
|
||||
+ adjust);
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return qMax(0, indent + adjust);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user