Skip to content

Commit

Permalink
fix neutral elements order in multiple lines (#4173)
Browse files Browse the repository at this point in the history
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
  • Loading branch information
mohad12211 and pajlada authored Nov 25, 2022
1 parent 330e0a9 commit fe2a9cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Bugfix: Fixed crash happening when QuickSwitcher is used with a popout window. (#4187)
- Bugfix: Fixed low contrast of text in settings tooltips. (#4188)
- Bugfix: Fixed being unable to see the usercard of VIPs who have Asian language display names. (#4174)
- Bugfix: Fixed messages where Right-to-Left order is mixed in multiple lines. (#4173)
- Bugfix: Fixed the wrong right-click menu showing in the chat input box. (#4177)
- Bugfix: Fixed popup windows not appearing/minimizing correctly on the Windows taskbar. (#4181)

Expand Down
13 changes: 7 additions & 6 deletions src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void MessageLayoutContainer::begin(int width, float scale, MessageFlags flags)
this->dotdotdotWidth_ = mediumFontMetrics.horizontalAdvance("...");
this->canAddMessages_ = true;
this->isCollapsed_ = false;
this->wasPrevReversed_ = false;
}

void MessageLayoutContainer::clear()
Expand Down Expand Up @@ -272,7 +273,6 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex)

std::vector<int> correctSequence;
std::stack<int> swappedSequence;
bool wasPrevReversed = false;

// we reverse a sequence of words if it's opposite to the text direction
// the second condition below covers the possible three cases:
Expand All @@ -291,18 +291,19 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex)
for (int i = startIndex; i <= endIndex; i++)
{
if (isNeutral(this->elements_[i]->getText()) &&
((this->first == FirstWord::RTL && !wasPrevReversed) ||
(this->first == FirstWord::LTR && wasPrevReversed)))
((this->first == FirstWord::RTL && !this->wasPrevReversed_) ||
(this->first == FirstWord::LTR && this->wasPrevReversed_)))
{
this->elements_[i]->reversedNeutral = true;
}
if (((this->elements_[i]->getText().isRightToLeft() !=
(this->first == FirstWord::RTL)) &&
!isNeutral(this->elements_[i]->getText())) ||
(isNeutral(this->elements_[i]->getText()) && wasPrevReversed))
(isNeutral(this->elements_[i]->getText()) &&
this->wasPrevReversed_))
{
swappedSequence.push(i);
wasPrevReversed = true;
this->wasPrevReversed_ = true;
}
else
{
Expand All @@ -312,7 +313,7 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex)
swappedSequence.pop();
}
correctSequence.push_back(i);
wasPrevReversed = false;
this->wasPrevReversed_ = false;
}
}
while (!swappedSequence.empty())
Expand Down
1 change: 1 addition & 0 deletions src/messages/layouts/MessageLayoutContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct MessageLayoutContainer {
int dotdotdotWidth_ = 0;
bool canAddMessages_ = true;
bool isCollapsed_ = false;
bool wasPrevReversed_ = false;

std::vector<std::unique_ptr<MessageLayoutElement>> elements_;
std::vector<Line> lines_;
Expand Down

0 comments on commit fe2a9cc

Please sign in to comment.