App icon indicating copy to clipboard operation
App copied to clipboard

[Needs regression test steps] [$1000] When copy pasting message containing email/links, email address/link occupies new line.

Open mvtglobally opened this issue 4 years ago • 126 comments

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:

Typed a message [email protected] is my email. [email protected] is someone else's email. Copied and pasted in the text box below

Expected Result:

Text should copy in the same line

Actual Result:

When copy pasting message containing email/links, email address/link occupies new line.

Workaround:

unknown

Platform:

Where is this issue occurring?

  • Web
  • Desktop App

Version Number: 1.1.69-2 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation Screenshot 2022-05-26 at 12 19 53 PM

Expensify/Expensify Issue URL: Issue reported by: @MonilBhavsar Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1653548218883739

Job Post: https://www.upwork.com/jobs/~01e09832b6e53bb854

View all open jobs on GitHub

mvtglobally avatar May 31 '22 05:05 mvtglobally

Triggered auto assignment to @Julesssss (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

melvin-bot[bot] avatar May 31 '22 05:05 melvin-bot[bot]

Reproduced, this should be fixed.

Julesssss avatar Jun 01 '22 14:06 Julesssss

Triggered auto assignment to @kevinksullivan (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

melvin-bot[bot] avatar Jun 01 '22 14:06 melvin-bot[bot]

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

melvin-bot[bot] avatar Jun 02 '22 22:06 melvin-bot[bot]

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

melvin-bot[bot] avatar Jun 02 '22 22:06 melvin-bot[bot]

Hmm I wonder why I got assigned if @Julesssss is an ECM and is still assigned as well 🤔 @Julesssss should I keep myself assigned to this one?

luacmartins avatar Jun 03 '22 14:06 luacmartins

Odd, I was OOO but I didn't think auto-assignment was smart enough to know that? Anyway, I'll keep it 👍

Julesssss avatar Jun 06 '22 09:06 Julesssss

You can do this. Please share your proposal.

parasharrajat avatar Jun 07 '22 07:06 parasharrajat

Proposals :

Hey, There is a method in CopySelectionHelper.js file

 copySelectionToClipboard() {
      const selectionMarkdown = SelectionScraper.getAsMarkdown();
      Clipboard.setString(selectionMarkdown);
  }

const getAsMarkdown = () => {
    const selectionHtml = getHTMLOfSelection();
    console.log("getMarkdown",selectionHtml);

    const domRepresentation = parseDocument(selectionHtml);
    domRepresentation.children = _.map(domRepresentation.children, c => replaceNodes(c));

    const newHtml = render(domRepresentation);

    const parser = new ExpensiMark();

    return parser.htmlToMarkdown(newHtml);
};

Above method is converting the copied text to HTML then to markdown.

There are two options we can have to solve this issue:

1.) We can update the getHtmlOfSelection() for selected text which is being used while converting it into markdown as below

const getHTMLOfSelection=()=>{
   if (window.getSelection) {
       const selection = window.getSelection().toString();
       const parser = new ExpensiMark();
       return parser.replace(selection);  
    }

     // If browser doesn't support Selection API, returns empty string.
     return '';
  
}

since, parser.replace() method is already being used in while we are trying to edit a comment, we can use the same method for selection !

2.) We can set the selected text in clipboard as a plain text which is being selected by updating copySelectionToClipboard() method as below.

copySelectionToClipboard() {
      if(window.getSelection())
       Clipboard.setString(window.getSelection().toString());
   }

or by updating current getHTMLOfSelection() as returning

             return div.innerText;

instead of

            return div.innerHTML;

NehaSantani avatar Jun 07 '22 11:06 NehaSantani

Hey @NehaSantani, thanks for the proposal. Did you test this solution on local setup?

How will you convert the text to Markdown?

parasharrajat avatar Jun 08 '22 18:06 parasharrajat

Hi @parasharrajat, The text is being converted into MarkDown in the similar manner like it is currently there using below method

index.js in /SelectionScraper.js

const getAsMarkdown = () => {
    const selectionHtml = getHTMLOfSelection();

    const domRepresentation = parseDocument(selectionHtml);
    domRepresentation.children = _.map(domRepresentation.children, c => replaceNodes(c));

    const newHtml = render(domRepresentation);

    const parser = new ExpensiMark();

    return parser.htmlToMarkdown(newHtml);
};

which inturn is called from below method

 copySelectionToClipboard() {
        const selectionMarkdown = SelectionScraper.getAsMarkdown();
        Clipboard.setString(selectionMarkdown);
    }

The whole conversion currently in the code is going like this (selectedText -----> HTML ------> Markdown)

However, the issue is inside HTML conversion of text! Actual Issue: The code done inside getHTMLOfSelection() method is returning HTML with some default style tags which is appending it to next line after converting into markdown.

The only change we need to do to solve the issue mentioned is inside getHTMLOfSelection() method which is called from getAsMarkdown() method.

Updated getHTMLofSelection().

index.js in /SelectionScaper.js

const getHTMLOfSelection = () => {
    if (window.getSelection()) {
    const selection = window.getSelection().toString();
    const parser = new ExpensiMark();
    return parser.replace(selection);  
 }  // If browser doesn't support Selection API, returns empty string.
 return '';
}

My proposal to use above code in getHTMLOfSelection() method is because we are already using parser.replace to convert it to html while editing a message!

Also,Yes i tested it in local. attached is the Recording for the same.

https://user-images.githubusercontent.com/4989101/172761596-2c5bcda3-d33b-4678-ad6e-709e18ed2a2f.mov

NehaSantani avatar Jun 09 '22 04:06 NehaSantani

Try this to copy chat between two messages. Start from bottom to the third last line(Hi Neha) of the previous message. Then paste it on composer and let me know what output you get.

parasharrajat avatar Jun 09 '22 12:06 parasharrajat

Hey sure!

https://user-images.githubusercontent.com/4989101/172853465-5313f8bd-19aa-4f76-adae-6bc085bb5cc8.mov

Is there any difference, that is missed!

NehaSantani avatar Jun 09 '22 13:06 NehaSantani

I mean try to copy two blocks of messages. Select everything in this image. image

parasharrajat avatar Jun 09 '22 13:06 parasharrajat

This way?

https://user-images.githubusercontent.com/4989101/172856353-e9ac2ece-fa0c-4536-9c9f-bd112141eebb.mov

NehaSantani avatar Jun 09 '22 13:06 NehaSantani

@parasharrajat Is this the expected result?

NehaSantani avatar Jun 09 '22 13:06 NehaSantani

Oh, I see that you don't have used bold italic formatting in your messages. Could you please edit them to use bold and italic (also use quotes via >) in the text and then try the same thing? Thanks

parasharrajat avatar Jun 09 '22 13:06 parasharrajat

https://user-images.githubusercontent.com/4989101/172863073-be2f777e-7ea0-46bc-8eef-9be4fa349e80.mov

Also, if you have any specific text to be tested with styles(bold,italic,quotes) you can send me! I will record for that aswell!

NehaSantani avatar Jun 09 '22 13:06 NehaSantani

Ok, thanks for sharing. I am amazed to see that it is working. How is your function getHTMLOfSelection converts elements with data-testid to proper tags?

const getHTMLOfSelection = () => { if (window.getSelection()) { const selection = window.getSelection().toString(); const parser = new ExpensiMark(); return parser.replace(selection);
} // If browser doesn't support Selection API, returns empty string. return ''; }

window.getSelection().toString() gives string neither markdown nor HTML. Then how are you getting HTML. parser.replace(selection); converts MD to HTML.

parasharrajat avatar Jun 09 '22 15:06 parasharrajat

Not overdue

Julesssss avatar Jun 13 '22 19:06 Julesssss