forked from qt-creator/qt-creator
ClangFormat: Fix utf8 symbol indentation
Fixes: QTCREATORBUG-29927 Change-Id: I5a5a326e13cbe3a874a66e275ded0c6dea9964d7 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -91,6 +91,7 @@ private slots:
|
||||
void testIndentInitializeVector();
|
||||
void testIndentFunctionArgumentOnNewLine();
|
||||
void testIndentCommentOnNewLine();
|
||||
void testUtf8SymbolLine();
|
||||
|
||||
private:
|
||||
void insertLines(const std::vector<QString> &lines);
|
||||
|
Reference in New Issue
Block a user