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.
|
// A comment at the end of the line appears to prevent clang-format from removing line breaks.
|
||||||
if (dummyText == "/*//*/" || dummyText.isEmpty()) {
|
if (dummyText == "/*//*/" || dummyText.isEmpty()) {
|
||||||
if (block.previous().isValid()) {
|
if (block.previous().isValid()) {
|
||||||
const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer,
|
const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(),
|
||||||
block.blockNumber()) + block.previous().text().length();
|
buffer,
|
||||||
|
block.blockNumber())
|
||||||
|
+ block.previous().text().toUtf8().length();
|
||||||
buffer.insert(prevEndOffset, " //");
|
buffer.insert(prevEndOffset, " //");
|
||||||
extraLength += 3;
|
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
|
} // namespace ClangFormat::Internal
|
||||||
|
@@ -91,6 +91,7 @@ private slots:
|
|||||||
void testIndentInitializeVector();
|
void testIndentInitializeVector();
|
||||||
void testIndentFunctionArgumentOnNewLine();
|
void testIndentFunctionArgumentOnNewLine();
|
||||||
void testIndentCommentOnNewLine();
|
void testIndentCommentOnNewLine();
|
||||||
|
void testUtf8SymbolLine();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void insertLines(const std::vector<QString> &lines);
|
void insertLines(const std::vector<QString> &lines);
|
||||||
|
Reference in New Issue
Block a user