TextEditor: correctly highlight preedit text

Fixes: QTCREATORBUG-29134
Change-Id: I8c5cdab8c5b2e5a2380c9e4aeadaf1bd72e60e09
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2023-06-06 07:31:33 +02:00
parent 196245c8f6
commit 9091c99429
4 changed files with 91 additions and 5 deletions

View File

@@ -185,6 +185,28 @@ void GenerigHighlighterTests::testChange()
compareFormats(actualFormats.at(i), formatRanges.at(i));
}
void GenerigHighlighterTests::testPreeditText()
{
QTextBlock block = m_editor->textDocument()->document()->findBlockByNumber(2);
QVERIFY(block.isValid());
block.layout()->setPreeditArea(7, "uaf");
m_editor->textDocument()->syntaxHighlighter()->rehighlight();
const FormatRanges formatRanges = {{0, 4, toFormat(C_VISUAL_WHITESPACE)},
{4, 3, toFormat(C_TYPE)},
{10, 3, toFormat(C_TYPE)},
{13, 1, toFormat(C_FUNCTION)},
{14, 1, toFormat(C_VISUAL_WHITESPACE)},
{15, 6, toFormat(C_STRING)},
{21, 1, toFormat(C_FUNCTION)}};
const QList<QTextLayout::FormatRange> actualFormats = block.layout()->formats();
// full hash calculation for QTextCharFormat fails so just check the important entries of format
QCOMPARE(actualFormats.size(), formatRanges.size());
for (int i = 0; i < formatRanges.size(); ++i)
compareFormats(actualFormats.at(i), formatRanges.at(i));
}
void GenerigHighlighterTests::cleanupTestCase()
{
if (m_editor)