ClangFormat: Do not format text but indent only

Provide the separate infrastructure for the formatting
but use it only when QTC_FORMAT_INSTEAD_OF_INDENT is
provided in run environment.

Fixes: QTCREATORBUG-21447
Fixes: QTCREATORBUG-21459
Change-Id: I1ad6fe23f5de17016c0c7b18749c6977fc03a22b
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-11-13 07:29:21 +01:00
parent 9a85ce88a7
commit e9d0083ccd
7 changed files with 88 additions and 48 deletions

View File

@@ -7132,11 +7132,21 @@ void TextEditorWidget::setIfdefedOutBlocks(const QList<BlockRange> &blocks)
documentLayout->requestUpdate();
}
static bool applyFormattingInsteadOfIndentation()
{
constexpr const char option[] = "QTC_FORMAT_INSTEAD_OF_INDENT";
return qEnvironmentVariableIsSet(option);
}
void TextEditorWidget::format()
{
static bool formattingInsteadOfIndentation = applyFormattingInsteadOfIndentation();
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
d->m_document->autoIndent(cursor, QChar::Null, false);
if (formattingInsteadOfIndentation)
d->m_document->autoFormat(cursor);
else
d->m_document->autoIndent(cursor);
cursor.endEditBlock();
}