diff options
author | David Schulz <david.schulz@qt.io> | 2022-09-14 09:11:44 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-09-14 11:09:12 +0000 |
commit | c9dc54802c2c7fea66121f51cc35106e1df5235b (patch) | |
tree | adf7b1cad65d9d0e17453331d7af4f8884a02f87 /src/plugins/clangformat | |
parent | 60f11cf6371fd6f482d257c54a48070874dc4b73 (diff) |
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>
Diffstat (limited to 'src/plugins/clangformat')
-rw-r--r-- | src/plugins/clangformat/clangformatbaseindenter.cpp | 10 | ||||
-rw-r--r-- | src/plugins/clangformat/clangformatbaseindenter.h | 3 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp index d214954c77..060809a36c 100644 --- a/src/plugins/clangformat/clangformatbaseindenter.cpp +++ b/src/plugins/clangformat/clangformatbaseindenter.cpp @@ -571,7 +571,8 @@ Utils::Text::Replacements ClangFormatBaseIndenter::format( Utils::Text::Replacements ClangFormatBaseIndenter::indentsFor(QTextBlock startBlock, const QTextBlock &endBlock, const QChar &typedChar, - int cursorPositionInEditor) + int cursorPositionInEditor, + bool trimTrailingWhitespace) { if (typedChar != QChar::Null && cursorPositionInEditor > 0 && m_doc->characterAt(cursorPositionInEditor - 1) == typedChar @@ -581,7 +582,7 @@ Utils::Text::Replacements ClangFormatBaseIndenter::indentsFor(QTextBlock startBl startBlock = reverseFindLastEmptyBlock(startBlock); const int startBlockPosition = startBlock.position(); - if (startBlockPosition > 0) { + if (trimTrailingWhitespace && startBlockPosition > 0) { trimRHSWhitespace(startBlock.previous()); if (cursorPositionInEditor >= 0) cursorPositionInEditor += startBlock.position() - startBlockPosition; @@ -656,13 +657,14 @@ void ClangFormatBaseIndenter::indentBlock(const QTextBlock &block, } int ClangFormatBaseIndenter::indentFor(const QTextBlock &block, - const TextEditor::TabSettings & /*tabSettings*/, + const TextEditor::TabSettings &tabSettings, int cursorPositionInEditor) { Utils::Text::Replacements toReplace = indentsFor(block, block, QChar::Null, - cursorPositionInEditor); + cursorPositionInEditor, + false); if (toReplace.empty()) return -1; diff --git a/src/plugins/clangformat/clangformatbaseindenter.h b/src/plugins/clangformat/clangformatbaseindenter.h index aa5290f4ff..27c5fc1edc 100644 --- a/src/plugins/clangformat/clangformatbaseindenter.h +++ b/src/plugins/clangformat/clangformatbaseindenter.h @@ -62,7 +62,8 @@ private: Utils::Text::Replacements indentsFor(QTextBlock startBlock, const QTextBlock &endBlock, const QChar &typedChar, - int cursorPositionInEditor); + int cursorPositionInEditor, + bool trimTrailingWhitespace = true); Utils::Text::Replacements replacements(QByteArray buffer, const QTextBlock &startBlock, const QTextBlock &endBlock, |