ClangFormat: do not remove trailing spaces on indent calculation

Fixes: QTCREATORBUG-28150
Change-Id: I6f7b18e1afefb96da28295a2c3654d1c1ced4308
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
David Schulz
2022-09-14 09:11:44 +02:00
parent 60f11cf637
commit c9dc54802c
2 changed files with 8 additions and 5 deletions

View File

@@ -571,7 +571,8 @@ Utils::Text::Replacements ClangFormatBaseIndenter::format(
Utils::Text::Replacements ClangFormatBaseIndenter::indentsFor(QTextBlock startBlock, Utils::Text::Replacements ClangFormatBaseIndenter::indentsFor(QTextBlock startBlock,
const QTextBlock &endBlock, const QTextBlock &endBlock,
const QChar &typedChar, const QChar &typedChar,
int cursorPositionInEditor) int cursorPositionInEditor,
bool trimTrailingWhitespace)
{ {
if (typedChar != QChar::Null && cursorPositionInEditor > 0 if (typedChar != QChar::Null && cursorPositionInEditor > 0
&& m_doc->characterAt(cursorPositionInEditor - 1) == typedChar && m_doc->characterAt(cursorPositionInEditor - 1) == typedChar
@@ -581,7 +582,7 @@ Utils::Text::Replacements ClangFormatBaseIndenter::indentsFor(QTextBlock startBl
startBlock = reverseFindLastEmptyBlock(startBlock); startBlock = reverseFindLastEmptyBlock(startBlock);
const int startBlockPosition = startBlock.position(); const int startBlockPosition = startBlock.position();
if (startBlockPosition > 0) { if (trimTrailingWhitespace && startBlockPosition > 0) {
trimRHSWhitespace(startBlock.previous()); trimRHSWhitespace(startBlock.previous());
if (cursorPositionInEditor >= 0) if (cursorPositionInEditor >= 0)
cursorPositionInEditor += startBlock.position() - startBlockPosition; cursorPositionInEditor += startBlock.position() - startBlockPosition;
@@ -656,13 +657,14 @@ void ClangFormatBaseIndenter::indentBlock(const QTextBlock &block,
} }
int ClangFormatBaseIndenter::indentFor(const QTextBlock &block, int ClangFormatBaseIndenter::indentFor(const QTextBlock &block,
const TextEditor::TabSettings & /*tabSettings*/, const TextEditor::TabSettings &tabSettings,
int cursorPositionInEditor) int cursorPositionInEditor)
{ {
Utils::Text::Replacements toReplace = indentsFor(block, Utils::Text::Replacements toReplace = indentsFor(block,
block, block,
QChar::Null, QChar::Null,
cursorPositionInEditor); cursorPositionInEditor,
false);
if (toReplace.empty()) if (toReplace.empty())
return -1; return -1;

View File

@@ -62,7 +62,8 @@ private:
Utils::Text::Replacements indentsFor(QTextBlock startBlock, Utils::Text::Replacements indentsFor(QTextBlock startBlock,
const QTextBlock &endBlock, const QTextBlock &endBlock,
const QChar &typedChar, const QChar &typedChar,
int cursorPositionInEditor); int cursorPositionInEditor,
bool trimTrailingWhitespace = true);
Utils::Text::Replacements replacements(QByteArray buffer, Utils::Text::Replacements replacements(QByteArray buffer,
const QTextBlock &startBlock, const QTextBlock &startBlock,
const QTextBlock &endBlock, const QTextBlock &endBlock,