fix: Limiting the height of a message that contains some RTL text causes a crash (#4168)

Co-authored-by: mohad12211 <51754973+mohad12211@users.noreply.github.com>
Fixes https://github.com/Chatterino/chatterino2/issues/4166
This commit is contained in:
nerix
2022-11-20 16:30:51 +01:00
committed by GitHub
parent 3924861a3d
commit 82d345bc76
3 changed files with 20 additions and 7 deletions
@@ -83,7 +83,7 @@ void MessageLayoutContainer::addElementNoLineBreak(
this->_addElement(element);
}
bool MessageLayoutContainer::canAddElements()
bool MessageLayoutContainer::canAddElements() const
{
return this->canAddMessages_;
}
@@ -264,7 +264,7 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex)
int startIndex = static_cast<int>(this->lineStart_);
int endIndex = static_cast<int>(this->elements_.size()) - 1;
if (firstTextIndex >= endIndex)
if (firstTextIndex >= endIndex || startIndex >= this->elements_.size())
{
return;
}
@@ -331,9 +331,12 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex)
this->currentX_ = this->elements_[startIndex]->getRect().left();
}
// manually do the first call with -1 as previous index
this->_addElement(this->elements_[correctSequence[0]].get(), false, -1);
if (this->canAddElements())
{
this->_addElement(this->elements_[correctSequence[0]].get(), false, -1);
}
for (int i = 1; i < correctSequence.size(); i++)
for (int i = 1; i < correctSequence.size() && this->canAddElements(); i++)
{
this->_addElement(this->elements_[correctSequence[i]].get(), false,
correctSequence[i - 1]);
@@ -446,7 +449,17 @@ void MessageLayoutContainer::end()
QSize(this->dotdotdotWidth_, this->textLineHeight_),
QColor("#00D80A"), FontStyle::ChatMediumBold, this->scale_);
// getApp()->themes->messages.textColors.system
if (this->first == FirstWord::RTL)
{
// Shift all elements in the next line to the left
for (int i = this->lines_.back().startIndex;
i < this->elements_.size(); i++)
{
QPoint prevPos = this->elements_[i]->getRect().topLeft();
this->elements_[i]->setPosition(
QPoint(prevPos.x() + this->dotdotdotWidth_, prevPos.y()));
}
}
this->_addElement(element, true);
this->isCollapsed_ = true;
}