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:
David Schulz
2016-01-13 14:32:23 +01:00
parent bc921b46a2
commit 9aa51d4857
22 changed files with 346 additions and 200 deletions

View File

@@ -98,34 +98,29 @@ static int paranthesesLevel(const QString &line)
return -1;
}
void CMakeIndenter::indentBlock(QTextDocument *doc, const QTextBlock &block, const QChar &typedChar, const TextEditor::TabSettings &tabSettings)
int CMakeIndenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc)
Q_UNUSED(typedChar)
QTextBlock previousBlock = block.previous();
// find the next previous block that is non-empty (contains non-whitespace characters)
while (previousBlock.isValid() && lineIsEmpty(previousBlock.text()))
previousBlock = previousBlock.previous();
if (previousBlock.isValid()) {
const QString previousLine = previousBlock.text();
const QString currentLine = block.text();
int indentation = tabSettings.indentationColumn(previousLine);
if (!previousBlock.isValid())
return 0;
if (lineStartsBlock(previousLine))
indentation += tabSettings.m_indentSize;
if (lineEndsBlock(currentLine))
indentation = qMax(0, indentation - tabSettings.m_indentSize);
const QString previousLine = previousBlock.text();
const QString currentLine = block.text();
int indentation = tabSettings.indentationColumn(previousLine);
// increase/decrease/keep the indentation level depending on if we have more opening or closing parantheses
indentation = qMax(0, indentation + tabSettings.m_indentSize * paranthesesLevel(previousLine));
if (lineStartsBlock(previousLine))
indentation += tabSettings.m_indentSize;
if (lineEndsBlock(currentLine))
indentation = qMax(0, indentation - tabSettings.m_indentSize);
tabSettings.indentLine(block, indentation);
} else {
// First line in whole document
tabSettings.indentLine(block, 0);
}
// increase/decrease/keep the indentation level depending on if we have more opening or closing parantheses
return qMax(0, indentation + tabSettings.m_indentSize * paranthesesLevel(previousLine));
}
} // namespace Internal
} // namespace CMakeProjectManager

View File

@@ -36,7 +36,8 @@ class CMAKE_EXPORT CMakeIndenter : public TextEditor::Indenter
{
public:
bool isElectricCharacter(const QChar &ch) const override;
void indentBlock(QTextDocument *doc, const QTextBlock &block, const QChar &typedChar, const TextEditor::TabSettings &tabSettings) override;
int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override;
};
} // namespace Internal