Describe the bug
Using the Copy User ID button includes the text "ID:" along with the user id
To Reproduce
Press copy user id button, paste
Expected behavior
ID number only to be copied
Screenshots

Chatterino version
9874bd7
@Mm2PL 馃榾
I also prefer this be changed. I can't really imagine a scenario where having the ID: part would be useful.
This is a side effect of how I made it. And makes sense that it should be changed. The way that the copying currently works is: the label is set to "ID: " + userId and then when the copy button is pressed the text is copied.
I see three ways of changing this:
"ID :" (TEXT_USER_ID), that would mean the interface would be less readable,addCopyableLabel() to only copy text that is meant to be copied,userIDLabel into two, one that would contain the "ID :" text the other one would contain the user id we meant to copy.
- changing
addCopyableLabel()to only copy text that is meant to be copied,
Personally, I like the idea of adding an additional parameter to addCopyableLabel that determines the text that should be copied. We could also use a boost::optional and default to the label text if boost::none is passed but I think that is too much effort.
I propose something like this:
void addCopyableLabel(LayoutCreator<QHBoxLayout> box, Label **assign, const QString ©Text)
{
auto label = box.emplace<Label>().assign(assign);
auto button = box.emplace<Button>();
button->setPixmap(getResources().buttons.copyDark);
button->setScaleIndependantSize(18, 18);
button->setDim(Button::Dim::Lots);
QObject::connect(button.getElement(), &Button::leftClicked,
[©Text] {
qApp->clipboard()->setText(copyText);
});
};
And the calls would then look like this:
addCopyableLabel(box, &this->ui_.nameLabel, this->userName_);
// [...]
addCopyableLabel(box, &this->ui_.userIDLabel, this->userId_);
Fix it by optionally storing a string in the properties of the label.
@leon-richardt In your solution the copyText shouldn't be a const reference since everywhere in the code this means copying the element, but instead a pointer since it means that there is unsafe access to an address. However I chose this approach over yours since it is fail safe and doesn't create invisible relations between the member variable and the callback.
Most helpful comment
Fix it by optionally storing a string in the properties of the label.
@leon-richardt In your solution the
copyTextshouldn't be a const reference since everywhere in the code this means copying the element, but instead a pointer since it means that there is unsafe access to an address. However I chose this approach over yours since it is fail safe and doesn't create invisible relations between the member variable and the callback.