Resort entities if needed after rtrim.
GitOrigin-RevId: f3124b2dc72e1b7858dde90133c5313025103603
This commit is contained in:
parent
718067e218
commit
532567a475
@ -3609,12 +3609,17 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
||||
entities.back().type == MessageEntity::Type::MentionName);
|
||||
entities.pop_back();
|
||||
}
|
||||
bool need_sort = false;
|
||||
for (auto &entity : entities) {
|
||||
if (entity.offset + entity.length > last_non_whitespace_utf16_offset + 1) {
|
||||
entity.length = last_non_whitespace_utf16_offset + 1 - entity.offset;
|
||||
need_sort = true;
|
||||
CHECK(entity.length > 0);
|
||||
}
|
||||
}
|
||||
if (need_sort) {
|
||||
std::sort(entities.begin(), entities.end());
|
||||
}
|
||||
|
||||
// ltrim
|
||||
size_t first_non_whitespaces_pos = 0;
|
||||
|
@ -793,6 +793,9 @@ TEST(MessageEntities, fix_formatted_text) {
|
||||
{td::MessageEntity::Type::Italic, 0, 1},
|
||||
{td::MessageEntity::Type::Bold, 2, 1},
|
||||
{td::MessageEntity::Type::Italic, 2, 1}});
|
||||
check_fix_formatted_text("a ", {{td::MessageEntity::Type::Italic, 0, 2}, {td::MessageEntity::Type::Bold, 0, 1}}, "a",
|
||||
{{td::MessageEntity::Type::Bold, 0, 1}, {td::MessageEntity::Type::Italic, 0, 1}}, false,
|
||||
false, false, false);
|
||||
check_fix_formatted_text("abc", {{td::MessageEntity::Type::Italic, 1, 1}, {td::MessageEntity::Type::Italic, 0, 1}},
|
||||
"abc", {{td::MessageEntity::Type::Italic, 0, 2}});
|
||||
check_fix_formatted_text("abc", {{td::MessageEntity::Type::Italic, 1, 1}, {td::MessageEntity::Type::Italic, 1, 1}},
|
||||
|
Loading…
Reference in New Issue
Block a user