From c5029d23adadb27fdb0afb016e68fe411f3feb93 Mon Sep 17 00:00:00 2001 From: mohad12211 Date: Sat, 10 Jun 2023 02:26:21 +0300 Subject: [PATCH 1/2] Treat elements with usernames (mentions) as neutral elements --- CHANGELOG.md | 1 + src/messages/layouts/MessageLayoutContainer.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d3d2090a9c..0d0091da860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Minor: Added `/shoutout ` commands to shoutout specified user. (#4638) - Minor: Improved editing hotkeys. (#4628) - Bugfix: Fixed generation of crashdumps by the browser-extension process when the browser was closed. (#4667) +- Bugfix: Fix spacing issue with mentions inside RTL text. (#4677) - Dev: Added command to set Qt's logging filter/rules at runtime (`/c2-set-logging-rules`). (#4637) - Dev: Added the ability to see & load custom themes from the Themes directory. No stable promises are made of this feature, changes might be made that breaks custom themes without notice. (#4570) - Dev: Added test cases for emote and tab completion. (#4644) diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index 540e9dfac43..e09d5cca424 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -276,6 +276,11 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex) // 2 - in LTR mode, the previous word should be RTL (i.e. reversed) for (int i = startIndex; i <= endIndex; i++) { + bool neutral = isNeutral(this->elements_[i]->getText()) || + this->elements_[i]->getFlags().hasAny( + {MessageElementFlag::BoldUsername, + MessageElementFlag::NonBoldUsername}); + if (isNeutral(this->elements_[i]->getText()) && ((this->first == FirstWord::RTL && !this->wasPrevReversed_) || (this->first == FirstWord::LTR && this->wasPrevReversed_))) @@ -284,9 +289,8 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex) } if (((this->elements_[i]->getText().isRightToLeft() != (this->first == FirstWord::RTL)) && - !isNeutral(this->elements_[i]->getText())) || - (isNeutral(this->elements_[i]->getText()) && - this->wasPrevReversed_)) + !neutral) || + (neutral && this->wasPrevReversed_)) { swappedSequence.push(i); this->wasPrevReversed_ = true; From 74f012f8092d97b443659b2afef28307489d1777 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 10 Jun 2023 14:00:16 +0200 Subject: [PATCH 2/2] Clean up logic Also store a reference to the element --- .../layouts/MessageLayoutContainer.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index e09d5cca424..8f279788040 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -276,21 +276,24 @@ void MessageLayoutContainer::reorderRTL(int firstTextIndex) // 2 - in LTR mode, the previous word should be RTL (i.e. reversed) for (int i = startIndex; i <= endIndex; i++) { - bool neutral = isNeutral(this->elements_[i]->getText()) || - this->elements_[i]->getFlags().hasAny( - {MessageElementFlag::BoldUsername, - MessageElementFlag::NonBoldUsername}); + auto &element = this->elements_[i]; - if (isNeutral(this->elements_[i]->getText()) && + const auto neutral = isNeutral(element->getText()); + const auto neutralOrUsername = + neutral || + element->getFlags().hasAny({MessageElementFlag::BoldUsername, + MessageElementFlag::NonBoldUsername}); + + if (neutral && ((this->first == FirstWord::RTL && !this->wasPrevReversed_) || (this->first == FirstWord::LTR && this->wasPrevReversed_))) { - this->elements_[i]->reversedNeutral = true; + element->reversedNeutral = true; } - if (((this->elements_[i]->getText().isRightToLeft() != + if (((element->getText().isRightToLeft() != (this->first == FirstWord::RTL)) && - !neutral) || - (neutral && this->wasPrevReversed_)) + !neutralOrUsername) || + (neutralOrUsername && this->wasPrevReversed_)) { swappedSequence.push(i); this->wasPrevReversed_ = true;