Skip to content

Commit

Permalink
Fixed too much text being copied when copying chat messages (#4812)
Browse files Browse the repository at this point in the history
* fix: selection copying too much

* chore: add changelog entry

* Update changelog entry

---------

Co-authored-by: Rasmus Karlsson <[email protected]>
  • Loading branch information
Nerixyz and pajlada authored Sep 17, 2023
1 parent dc62e82 commit 3265df7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Bugfix: Fixed Usercard popup not floating on tiling WMs on Linux when "Automatically close user popup when it loses focus" setting is enabled. (#3511)
- Bugfix: Fixed selection of tabs after closing a tab when using "Live Tabs Only". (#4770)
- Bugfix: Fixed input in reply thread popup losing focus when dragging. (#4815)
- Bugfix: Fixed too much text being copied when copying chat messages. (#4812)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
- Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767)
- Dev: Tests now run on Ubuntu 22.04 instead of 20.04 to loosen C++ restrictions in tests. (#4774)
Expand Down
9 changes: 7 additions & 2 deletions src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ void MessageLayoutContainer::end()
this->lines_.back().endIndex = this->elements_.size();
this->lines_.back().endCharIndex = this->charIndex_;
}

if (!this->elements_.empty())
{
this->elements_.back()->setTrailingSpace(false);
}
}

bool MessageLayoutContainer::canCollapse()
Expand Down Expand Up @@ -849,15 +854,15 @@ void MessageLayoutContainer::addSelectionText(QString &str, uint32_t from,
element->addCopyTextToString(str, from - index, to - index);
first = false;

if (index + indexCount > to)
if (index + indexCount >= to)
{
break;
}
}
}
else
{
if (index + indexCount > to)
if (index + indexCount >= to)
{
element->addCopyTextToString(str, 0, to - index);
break;
Expand Down
12 changes: 6 additions & 6 deletions src/messages/layouts/MessageLayoutElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ void ImageLayoutElement::addCopyTextToString(QString &str, uint32_t from,
{
str += emoteElement->getEmote()->getCopyString();
str = TwitchEmotes::cleanUpEmoteCode(str);
if (this->hasTrailingSpace())
if (this->hasTrailingSpace() && to >= 2)
{
str += " ";
str += ' ';
}
}
}
Expand Down Expand Up @@ -217,9 +217,9 @@ void LayeredImageLayoutElement::addCopyTextToString(QString &str, uint32_t from,
{
// cleaning is taken care in call
str += layeredEmoteElement->getCleanCopyString();
if (this->hasTrailingSpace())
if (this->hasTrailingSpace() && to >= 2)
{
str += " ";
str += ' ';
}
}
}
Expand Down Expand Up @@ -416,9 +416,9 @@ void TextLayoutElement::addCopyTextToString(QString &str, uint32_t from,
{
str += this->getText().mid(from, to - from);

if (this->hasTrailingSpace())
if (this->hasTrailingSpace() && to > this->getText().length())
{
str += " ";
str += ' ';
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ QString ChannelView::getSelectedText()
: layout->getLastCharacterIndex() + 1;

layout->addSelectionText(result, from, to);

if (msg != indexEnd)
{
result += '\n';
}
}

return result;
Expand Down

0 comments on commit 3265df7

Please sign in to comment.