diff options
author | Artem Sokolovskii <[email protected]> | 2023-12-08 11:49:01 +0100 |
---|---|---|
committer | Artem Sokolovskii <[email protected]> | 2023-12-08 17:48:39 +0000 |
commit | ee75c7276b9ba9fc01f0182d45547038567b6e93 (patch) | |
tree | 3eb504543d7b3c54f3f3c57ecffc829d9f9b6638 | |
parent | 2f49c0830efafe5f9f87a313ed0faa076a3c755e (diff) |
ClangFormat: Fix utf8 symbol indentationv12.0.1
Fixes: QTCREATORBUG-29927
Change-Id: I5a5a326e13cbe3a874a66e275ded0c6dea9964d7
Reviewed-by: Christian Kandeler <[email protected]>
Reviewed-by: <[email protected]>
-rw-r--r-- | src/plugins/clangformat/clangformatbaseindenter.cpp | 6 | ||||
-rw-r--r-- | src/plugins/clangformat/tests/clangformat-test.cpp | 16 | ||||
-rw-r--r-- | src/plugins/clangformat/tests/clangformat-test.h | 1 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp index 6903491fb0c..605ed2801c0 100644 --- a/src/plugins/clangformat/clangformatbaseindenter.cpp +++ b/src/plugins/clangformat/clangformatbaseindenter.cpp @@ -316,8 +316,10 @@ int forceIndentWithExtraText(QByteArray &buffer, // A comment at the end of the line appears to prevent clang-format from removing line breaks. if (dummyText == "/*//*/" || dummyText.isEmpty()) { if (block.previous().isValid()) { - const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer, - block.blockNumber()) + block.previous().text().length(); + const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), + buffer, + block.blockNumber()) + + block.previous().text().toUtf8().length(); buffer.insert(prevEndOffset, " //"); extraLength += 3; } diff --git a/src/plugins/clangformat/tests/clangformat-test.cpp b/src/plugins/clangformat/tests/clangformat-test.cpp index 80d2cc4da90..a4a85cf9065 100644 --- a/src/plugins/clangformat/tests/clangformat-test.cpp +++ b/src/plugins/clangformat/tests/clangformat-test.cpp @@ -730,4 +730,20 @@ void ClangFormatTest::testIndentCommentOnNewLine() })); } +void ClangFormatTest::testUtf8SymbolLine() +{ + insertLines({"int main()", + "{", + " cout << \"ä\" << endl;", + " return 0;", + "}"}); + m_indenter->indent(*m_cursor, QChar::Null, TextEditor::TabSettings()); + QCOMPARE(documentLines(), + (std::vector<QString>{"int main()", + "{", + " cout << \"ä\" << endl;", + " return 0;", + "}"})); +} + } // namespace ClangFormat::Internal diff --git a/src/plugins/clangformat/tests/clangformat-test.h b/src/plugins/clangformat/tests/clangformat-test.h index 494ebc85daf..d1dba9a13f2 100644 --- a/src/plugins/clangformat/tests/clangformat-test.h +++ b/src/plugins/clangformat/tests/clangformat-test.h @@ -91,6 +91,7 @@ private slots: void testIndentInitializeVector(); void testIndentFunctionArgumentOnNewLine(); void testIndentCommentOnNewLine(); + void testUtf8SymbolLine(); private: void insertLines(const std::vector<QString> &lines); |