From fe2a9ccbff8c4abad0b6df4a1bd279ad9fdf531a Mon Sep 17 00:00:00 2001 From: mohad12211 <51754973+mohad12211@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:24:28 +0300 Subject: [PATCH] fix neutral elements order in multiple lines (#4173) Co-authored-by: Rasmus Karlsson --- CHANGELOG.md | 1 + src/messages/layouts/MessageLayoutContainer.cpp | 13 +++++++------ src/messages/layouts/MessageLayoutContainer.hpp | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a091985e3..2b803e1dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index 1415bcd6d..037c15b3c 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -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() @@ -272,7 +273,6 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex) std::vector correctSequence; std::stack 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: @@ -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 { @@ -312,7 +313,7 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex) swappedSequence.pop(); } correctSequence.push_back(i); - wasPrevReversed = false; + this->wasPrevReversed_ = false; } } while (!swappedSequence.empty()) diff --git a/src/messages/layouts/MessageLayoutContainer.hpp b/src/messages/layouts/MessageLayoutContainer.hpp index 7d2ad63b4..d17df31ed 100644 --- a/src/messages/layouts/MessageLayoutContainer.hpp +++ b/src/messages/layouts/MessageLayoutContainer.hpp @@ -128,6 +128,7 @@ private: int dotdotdotWidth_ = 0; bool canAddMessages_ = true; bool isCollapsed_ = false; + bool wasPrevReversed_ = false; std::vector> elements_; std::vector lines_;