Skip to content
Snippets Groups Projects
Commit fbbac52d authored by AndreyL ProductEngine's avatar AndreyL ProductEngine
Browse files

MAINT-8044 Fixed crash in LLFloaterIMNearbyChatToastPanel::init();

algorythmic improvement for MAINT-6891
parent 72b0ce5c
No related branches found
No related tags found
No related merge requests found
...@@ -242,27 +242,28 @@ void LLFloaterIMNearbyChatToastPanel::init(LLSD& notification) ...@@ -242,27 +242,28 @@ void LLFloaterIMNearbyChatToastPanel::init(LLSD& notification)
S32 chars_in_line = mMsgText->getRect().getWidth() / messageFont->getWidth("c"); S32 chars_in_line = mMsgText->getRect().getWidth() / messageFont->getWidth("c");
S32 max_lines = notification["available_height"].asInteger() / (mMsgText->getTextPixelHeight() + 4); S32 max_lines = notification["available_height"].asInteger() / (mMsgText->getTextPixelHeight() + 4);
S32 new_line_chars = std::count(messageText.begin(), messageText.end(), '\n'); int lines = 0;
S32 lines_count = (messageText.size() - new_line_chars) / chars_in_line + new_line_chars + 1; int chars = 0;
//Remove excessive chars if message is not fit in available height. MAINT-6891 //Remove excessive chars if message does not fit in available height. MAINT-6891
if(lines_count > max_lines) std::string::iterator it;
for (it = messageText.begin(); it < messageText.end() && lines < max_lines; it++)
{ {
while(lines_count > max_lines) if (*it == '\n')
++lines;
else
++chars;
if (chars >= chars_in_line)
{ {
std::size_t nl_pos = messageText.rfind('\n'); chars = 0;
if (nl_pos != std::string::npos) ++lines;
{
nl_pos = nl_pos > messageText.length() - chars_in_line? nl_pos : messageText.length() - chars_in_line;
messageText.erase(messageText.begin() + nl_pos, messageText.end());
}
else
{
messageText.erase(messageText.end() - chars_in_line, messageText.end());
}
new_line_chars = std::count(messageText.begin(), messageText.end(), '\n');
lines_count = (messageText.size() - new_line_chars) / chars_in_line + new_line_chars;
} }
}
if (it < messageText.end())
{
messageText.erase(it, messageText.end());
messageText += " ..."; messageText += " ...";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment