Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed too much text being copied when copying chat messages #4812

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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