fix: sort elements after RTL reordering (#5525)

This commit is contained in:
nerix
2024-07-28 12:29:29 +02:00
committed by GitHub
parent 5fc4309e0e
commit 5ee5abf5b2
4 changed files with 28 additions and 13 deletions
+10 -13
View File
@@ -118,34 +118,31 @@ TEST_P(MessageLayoutContainerTest, RtlReordering)
MessageElementFlag::TwitchEmote,
});
}
container.breakLine();
container.endLayout();
ASSERT_EQ(container.line_, 1) << "unexpected linebreak";
// message layout elements ordered by x position
std::vector<MessageLayoutElement *> ordered;
ordered.reserve(container.elements_.size());
int x = -1;
for (const auto &el : container.elements_)
{
ordered.push_back(el.get());
ASSERT_LT(x, el->getRect().x());
x = el->getRect().x();
}
std::ranges::sort(ordered, [](auto *a, auto *b) {
return a->getRect().x() < b->getRect().x();
});
QString got;
for (const auto &el : ordered)
for (const auto &el : container.elements_)
{
if (!got.isNull())
{
got.append(' ');
}
if (dynamic_cast<ImageLayoutElement *>(el))
if (dynamic_cast<ImageLayoutElement *>(el.get()))
{
el->addCopyTextToString(got);
ASSERT_TRUE(got.endsWith(' '));
got.chop(1);
if (el->hasTrailingSpace())
{
got.chop(1);
}
}
else
{