Chatterino2: Copy User ID button includes "ID:" text

Created on 28 Sep 2019  路  5Comments  路  Source: Chatterino/chatterino2

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
image

Chatterino version
9874bd7

bug

Most helpful comment

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.

All 5 comments

@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:

  • getting rid of "ID :" (TEXT_USER_ID), that would mean the interface would be less readable,
  • changing addCopyableLabel() to only copy text that is meant to be copied,
  • splitting the 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 &copyText)
{
    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,
                     [&copyText] {
                         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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SaDiablo picture SaDiablo  路  3Comments

Oscillate1 picture Oscillate1  路  3Comments

doximanman picture doximanman  路  3Comments

TETYYS picture TETYYS  路  3Comments

Glass47 picture Glass47  路  3Comments