@@ -284,9 +284,10 @@ int MessageLayout::getSelectionIndex(QPoint position)
|
||||
return this->container_->getSelectionIndex(position);
|
||||
}
|
||||
|
||||
void MessageLayout::addSelectionText(QString &str, int from, int to)
|
||||
void MessageLayout::addSelectionText(QString &str, int from, int to,
|
||||
CopyMode copymode)
|
||||
{
|
||||
this->container_->addSelectionText(str, from, to);
|
||||
this->container_->addSelectionText(str, from, to, copymode);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/FlagsEnum.hpp"
|
||||
|
||||
#include <QPixmap>
|
||||
@@ -54,7 +55,8 @@ public:
|
||||
const MessageLayoutElement *getElementAt(QPoint point);
|
||||
int getLastCharacterIndex() const;
|
||||
int getSelectionIndex(QPoint position);
|
||||
void addSelectionText(QString &str, int from = 0, int to = INT_MAX);
|
||||
void addSelectionText(QString &str, int from = 0, int to = INT_MAX,
|
||||
CopyMode copymode = CopyMode::Everything);
|
||||
|
||||
// Misc
|
||||
bool isDisabled() const;
|
||||
|
||||
@@ -505,33 +505,41 @@ int MessageLayoutContainer::getLastCharacterIndex() const
|
||||
return this->lines_.back().endCharIndex;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to)
|
||||
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to,
|
||||
CopyMode copymode)
|
||||
{
|
||||
int index = 0;
|
||||
bool first = true;
|
||||
|
||||
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements_) {
|
||||
int c = ele->getSelectionIndexCount();
|
||||
for (auto &element : this->elements_) {
|
||||
if (copymode == CopyMode::OnlyTextAndEmotes) {
|
||||
if (element->getCreator().getFlags().hasAny(
|
||||
{MessageElementFlag::Timestamp,
|
||||
MessageElementFlag::Username, MessageElementFlag::Badges}))
|
||||
continue;
|
||||
}
|
||||
|
||||
auto indexCount = element->getSelectionIndexCount();
|
||||
|
||||
if (first) {
|
||||
if (index + c > from) {
|
||||
ele->addCopyTextToString(str, from - index, to - index);
|
||||
if (index + indexCount > from) {
|
||||
element->addCopyTextToString(str, from - index, to - index);
|
||||
first = false;
|
||||
|
||||
if (index + c > to) {
|
||||
if (index + indexCount > to) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (index + c > to) {
|
||||
ele->addCopyTextToString(str, 0, to - index);
|
||||
if (index + indexCount > to) {
|
||||
element->addCopyTextToString(str, 0, to - index);
|
||||
break;
|
||||
} else {
|
||||
ele->addCopyTextToString(str);
|
||||
element->addCopyTextToString(str);
|
||||
}
|
||||
}
|
||||
|
||||
index += c;
|
||||
index += indexCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/FlagsEnum.hpp"
|
||||
#include "messages/Selection.hpp"
|
||||
#include "messages/layouts/MessageLayoutElement.hpp"
|
||||
@@ -74,7 +75,7 @@ struct MessageLayoutContainer {
|
||||
// selection
|
||||
int getSelectionIndex(QPoint point);
|
||||
int getLastCharacterIndex() const;
|
||||
void addSelectionText(QString &str, int from, int to);
|
||||
void addSelectionText(QString &str, int from, int to, CopyMode copymode);
|
||||
|
||||
bool isCollapsed();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user