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

[$1000] Chat - Copy-pasting emoji names with keyboard shortcut doesn't paste the right emoji name #24399

Closed
2 of 6 tasks
lanitochka17 opened this issue Aug 11, 2023 · 43 comments
Closed
2 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 11, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Open an existing chat with a user
  2. Send message
  3. Apply emoji reaction on the sent message
  4. Right-click on the emjoi you applied on the message
  5. Triple click on the emoji name
  6. Press 'Ctrl + C' to copy the name
  7. Open emoji picker & paste the content to the search field

Expected Result:

The right emoji name should be pasted

Actual Result:

Wrong, long emoji name is pasted

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • Windows / Chrome
  • MacOS / Desktop

Version Number: 1.3.53.1

Reproducible in staging?: Yes

Reproducible in production?: Yes

If this was caught during regression testing, add the test name, ID and link from TestRail:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

Screencast.from.2023-08-03.13-55-36.mp4
Recording.2898.mp4

Expensify/Expensify Issue URL:

Issue reported by: @Natnael-Guchima

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1691060569144289

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01de88e41de20d9ce9
  • Upwork Job ID: 1691744740321337344
  • Last Price Increase: 2023-08-23
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 11, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 11, 2023

Triggered auto assignment to @bfitzexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Aug 11, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@jfquevedol2198
Copy link
Contributor

jfquevedol2198 commented Aug 11, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Chat - Copy-pasting emoji names with keyboard shortcut doesn't paste the right emoji name

What is the root cause of that problem?

Triple click selects avatar's svg style of nested reaction list image

What changes do you think we should make in order to solve the problem?

style={{maxWidth: variables.mobileResponsiveWidthBreakpoint}}

Add styles.userSelectNone in this line

style={{maxWidth: variables.mobileResponsiveWidthBreakpoint, ...styles.userSelectNone}}
Result
Screen.Recording.2023-08-11.at.9.43.20.AM.mov

What alternative solutions did you explore? (Optional)

N/A

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

When we triple-click the emoji code in the reaction list, the user's default avatar SVG style text also gets copied.

What is the root cause of that problem?

We can easily reproduce this issue by dragging the text selection to also include the avatar and copy it (ctrl/cmd+c), see the below video.

Screen.Recording.2023-08-11.at.15.36.51.mov

When we paste it, we will see the style text of the Avatar svg.
image

This happens because of our faulty selection logic. The selection is handled by SelectionScraper. When we are doing a selection copy (ctrl/cmd+c), SelectionScraper.getCurrentSelection will be called. To understand it better, we will use the example from the above video, that is selecting the user display name along with the default avatar.

First, it will get the HTML selection (getHTMLOfSelection). We can think of the HTML selection as selecting the HTML tag where our selection is present. In our case, it will select both avatar and display name elements. Nothing is wrong here.

Screenshot 2023-08-11 at 15 49 31

Next, we parse the HTML (parseDocument) to be an object, so we can easily manipulate the HTML attributes, children, etc. The manipulation is done by replaceNodes, which will clear all attributes and only keep the dom data that is a type of text.

let data;
// Encoding HTML chars '< >' in the text, because any HTML will be removed in stripHTML method.
if (dom.type === 'text') {
data = Str.htmlEncode(dom.data);
}

The problem is, inline style text is also a type of text, thus the Avatar SVG inline style text content is also included.
image

What changes do you think we should make in order to solve the problem?

The solution is to not include the style text content. There is no way to know whether the text is a CSS or a normal text, except from its parent. There are 3 ways to fix this (all in replaceNodes):

  1. Ignore the data (text) if the parent is a style tag
if (dom.type === 'text' && dom.parent.type !== 'style') {
    data = Str.htmlEncode(dom.data);
}

(the final dom will include both style and its content element but without any data)

  1. If the current element is a style tag, ignore its children
    if (dom.children) {
    domChildren = _.map(dom.children, (c) => replaceNodes(c, isChildOfEditorElement || !_.isEmpty(dom.attribs && dom.attribs[tagAttribute])));
    }
if (dom.children && dom.type !== 'style') {
    domChildren = _.map(dom.children, (c) => replaceNodes(...));
}

(the final dom will include style tag only without children)

  1. If the current element is a style tag, return an empty object (at the 1st line of the function).
if (dom.type === 'style') return {}

(the final dom won't include style tag)

I prefer the 3rd option.

@melvin-bot melvin-bot bot added the Overdue label Aug 14, 2023
@bfitzexpensify
Copy link
Contributor

Reproduced

@melvin-bot melvin-bot bot removed the Overdue label Aug 16, 2023
@bfitzexpensify bfitzexpensify added the External Added to denote the issue can be worked on by a contributor label Aug 16, 2023
@melvin-bot melvin-bot bot changed the title Chat - Copy-pasting emoji names with keyboard shortcut doesn't paste the right emoji name [$1000] Chat - Copy-pasting emoji names with keyboard shortcut doesn't paste the right emoji name Aug 16, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 16, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01de88e41de20d9ce9

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 16, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 16, 2023

Current assignee @bfitzexpensify is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 16, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak (External)

@bfitzexpensify
Copy link
Contributor

@eVoloshchak couple of proposals ready for review here

@melvin-bot melvin-bot bot removed the Overdue label Aug 22, 2023
@studentofcoding
Copy link
Contributor

studentofcoding commented Aug 22, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue

Copy-pasting emoji names with keyboard shortcut doesn't paste the right emoji name

What is the root cause of that problem?

The function attempts to get the selected text using SelectionScraper.getCurrentSelection() on useCopySelectionHelper.js hooks, but it does not handle the case when an emoji is selected. Instead, it assumes that the selected text is always a non-emoji text.

This leads to incorrect behavior when copying and pasting emoji names, as the function does not properly handle the case when an emoji is selected and tries to convert it to an emoji name.

What changes do you think we should make in order to solve the problem?

In this solution, we only need to use the getEmojiNameByUnicode function from EmojiUtils to get the emoji name by its Unicode on useCopySelectionHelper.js.

If an emoji name is found, we wrap it with colons : (which is the standard way to represent emojis in text), otherwise, we use the selected text as it is. This ensures that when an emoji is selected and copied, its name is copied instead of the emoji itself.

import {useEffect} from 'react';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import CONST from '../CONST';
import KeyboardShortcut from '../libs/KeyboardShortcut';
import Clipboard from '../libs/Clipboard';
import * as EmojiUtils from '../libs/EmojiUtils'; // Add EmojiUtils
import SelectionScraper from '../libs/SelectionScraper';

function copySelectionToClipboard() {
    const selection = SelectionScraper.getCurrentSelection();
    if (!selection) {
        return;
    }
    const parser = new ExpensiMark();
    const selectedEmojiName = EmojiUtils. getEmojiNameByUnicode(selection); //handleEmojiUnicode
    const textToCopy = selectedEmojiName ? `:${selectedEmojiName}:` : parser.htmlToMarkdown(selection); //copied text
    if (!Clipboard.canSetHtml()) {
        Clipboard.setString(textToCopy); //set textToCopy
        return;
    }
    Clipboard.setHtml(selection, parser.htmlToText(selection));
}

export default function useCopySelectionHelper() {
    useEffect(() => {
        const copyShortcutConfig = CONST.KEYBOARD_SHORTCUTS.COPY;
        const unsubscribeCopyShortcut = KeyboardShortcut.subscribe(
            copyShortcutConfig.shortcutKey,
            copySelectionToClipboard,
            copyShortcutConfig.descriptionKey,
            copyShortcutConfig.modifiers,
            false,
        );

        return unsubscribeCopyShortcut;
    }, []);
}

What alternative solutions did you explore? (Optional)

None

Demo

  • Copy & Paste Just the Name (double-click)
Copy.Pasting.Emoji.Names.Working.mov
  • Copy & Paste the Name with Colons (triple-click)
Copy.Pasting.Names.Colons.Working.mov

cc: @eVoloshchak

@joh42
Copy link
Contributor

joh42 commented Aug 22, 2023

@studentofcoding you need to triple-click so that the colons on each side (and hidden text) are copied. Just copying the text is not broken

@studentofcoding
Copy link
Contributor

studentofcoding commented Aug 23, 2023

Noted @joh42, the triple-click (or copy of all the colons) already covered in my solution too ;)

@bfitzexpensify bfitzexpensify added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Aug 23, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 23, 2023

Triggered auto assignment to @sakluger (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@Expensify Expensify deleted a comment from melvin-bot bot Aug 23, 2023
@bfitzexpensify
Copy link
Contributor

Heading ooo for a week - @sakluger, we're still in the proposal review stage here, so no action required from you at the moment. I can take this back over next week when I return.

@melvin-bot
Copy link

melvin-bot bot commented Aug 23, 2023

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@sakluger
Copy link
Contributor

@sobitneupane were you able to review proposals?

@sobitneupane
Copy link
Contributor

Thanks for the proposal everyone.

Proposal from @bernhardoj looks good to me.

🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Triggered auto assignment to @marcaaron, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@studentofcoding
Copy link
Contributor

studentofcoding commented Aug 29, 2023

Thanks for the proposal everyone.

Proposal from @bernhardoj looks good to me.

🎀 👀 🎀 C+ reviewed

Can you share why we have to do such a complicated changes where we only needed to include getEmojiNameByUnicode function like I Proposed ? Thanks

Copy.Pasting.Names.Colons.Working.mov

@sobitneupane
Copy link
Contributor

sobitneupane commented Aug 29, 2023

@studentofcoding The issue is not confined to emoji. Please go through the RCA section of the proposal for other instances of the issue.

@studentofcoding
Copy link
Contributor

As I recall, the expected behavior should be pasting the Emoji name with the : symbol

And for this could you share why we pursue A manual implementation of dom & nodes (that more like workaround) when we can simply use our EmojiUtils function instead?

Am I missing something @sobitneupane ?

@sobitneupane
Copy link
Contributor

And for this could you share why we pursue A manual implementation of dom & nodes (that more like workaround) when we can simply use our EmojiUtils function instead?

@studentofcoding We always try to find the root cause and solve the issue there. Root Cause Analysis in this proposal looks promising. Please let us know if you find any issue with the solution.

@studentofcoding
Copy link
Contributor

studentofcoding commented Aug 31, 2023

The thing is

  • The video demonstration is not on Emoji selection rather than a profile selection, when we only need to use EmojiUtils.getEmojiUnicode to handle the case, as introducing changes into SelectionScraper file might introduce regression & as we might want to keep the behavior on another component

Here is my RCA summary

The function attempts to get the selected text using SelectionScraper.getCurrentSelection() on useCopySelectionHelper.js hooks, but it does not handle the case when an emoji is selected. Instead, it assumes that the selected text is always a non-emoji text.`

But it's just my concern, and whoever gets selected, it's serve the same result

@melvin-bot
Copy link

melvin-bot bot commented Sep 1, 2023

@sakluger @sobitneupane @marcaaron @bfitzexpensify this issue is now 3 weeks old. There is one more week left before this issue breaks WAQ and will need to go internal. What needs to happen to get a PR in review this week? Please create a thread in #expensify-open-source to discuss. Thanks!

@marcaaron
Copy link
Contributor

@sakluger @bfitzexpensify this bug feels like a waste of time to me.

@sakluger
Copy link
Contributor

sakluger commented Sep 1, 2023

@marcaaron I agree, I didn't look too closely at the issue when it was reassigned to me. I'm not sure if anyone actually would copy the emoji name from that menu in real life, and if they did, it would likely be someone who could figure out how to edit the name to work properly.

@sakluger sakluger closed this as completed Sep 1, 2023
@studentofcoding
Copy link
Contributor

Could you share more why this is a waste of time @marcaaron ?

Also given mind that the user can and possibly do this, that behaviour itself its making this bug valid, no @sakluger ?

Im just want to ask and clarify things as its not clear why its abruptly being closed where this is a valid bug

Thanks

@bernhardoj
Copy link
Contributor

Agree with @studentofcoding. The bug itself is actually not specific to selecting the emoji code, but rather our SelectionScrapper logic includes text inside <style> tag into the selection. I see most of our SVG has <style> tag. I think it's low value but it can easily be reproduced by doing text selection.

@marcaaron
Copy link
Contributor

I'd give the same reasoning as @sakluger. It's just not really something that a user seems like they would do. I don't think anyone has said it's "invalid" though. The complexity in fixing it don't align with the value we would get by fixing it.

@studentofcoding
Copy link
Contributor

I'd give the same reasoning as @sakluger. It's just not really something that a user seems like they would do. I don't think anyone has said it's "invalid" though. The complexity in fixing it don't align with the value we would get by fixing it.

I beg to differ on the complexity in fixing it. In the end its just a simple fix, with using 'getEmojiNameByUnicode' from 'EmojiUtils'

With this in mind, did it really wasting the effort here?

@bernhardoj
Copy link
Contributor

@marcaaron The solution is actually very simple, as simple as one line

if (dom.type === 'style') return {}

Even the chance of user copying the emoji name from the reaction list is small, I think the fix worths the value as this issue happen to all text selection.

@spcheema
Copy link
Contributor

spcheema commented Sep 6, 2023

Apologies in advance if I'm not aligned with anyone's opinion.

I personally don't find this issue valuable to fix since it's not something a user will do in most cases.

I'd say if we keep on fixing such bugs saying simple or small then we will end up with not utilising available resources (C++ & internal team time, then testing team time and of course money is another player in the game).

Since we already reduced bounty price to make open source sustainable for long run.

@studentofcoding
Copy link
Contributor

Apologies in advance if I'm not aligned with anyone's opinion.

I personally don't find this issue valuable to fix since it's not something a user will do in most cases.

I'd say if we keep on fixing such bugs saying simple or small then we will end up with not utilising available resources (C++ & internal team time, then testing team time and of course money is another player in the game).

Since we already reduced bounty price to make open source sustainable for long run.

Thats totally ok, and I understand you POV, especially for Issue after the price reduction is announced

But in this case, 1. Its not a part of price reduction, and 2. Its a still a valid bug, and The solution is simple. Its just dont fair for external contributor, to close and change the procedure middle way dont you think?

On another aspect, I think I and @bernhardoj will understand if this issue are decreased to half ($500) as we also have a mechanism for low-priority bug

@studentofcoding
Copy link
Contributor

I'll wait for Internal Team to shed a light on this

@spcheema
Copy link
Contributor

spcheema commented Sep 6, 2023

Well if I am in the same boat and also feel in the same way you guys feel. But it's just not worth it, that's the only view I am having here.

@marcaaron
Copy link
Contributor

I'll defer to @sobitneupane as they should be managing this issue and selecting a proposal. The linked proposal has 3 different solutions. There is also various discussion happening and challenges to that proposal.

@sobitneupane Please be decisive, manage this conversation, and offer us a path forward. If the final proposal is clear and looks easy to implement then I will agree to reopen it and get it done.

@sobitneupane
Copy link
Contributor

sobitneupane commented Sep 7, 2023

I agree with @marcaaron and @sakluger. I don't think the issue carries much value. The reproduction step is very specific and rare. So, my vote is on closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
None yet
Development

No branches or pull requests