[Needs regression test steps] [$1000] When copy pasting message containing email/links, email address/link occupies new line.
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

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
Triggered auto assignment to @Julesssss (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Reproduced, this should be fixed.
Triggered auto assignment to @kevinksullivan (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (Exported)
Triggered auto assignment to @luacmartins (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
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?
Odd, I was OOO but I didn't think auto-assignment was smart enough to know that? Anyway, I'll keep it 👍
You can do this. Please share your proposal.
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;
Hey @NehaSantani, thanks for the proposal. Did you test this solution on local setup?
How will you convert the text to Markdown?
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
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.
Hey sure!
https://user-images.githubusercontent.com/4989101/172853465-5313f8bd-19aa-4f76-adae-6bc085bb5cc8.mov
Is there any difference, that is missed!
I mean try to copy two blocks of messages. Select everything in this image.

This way?
https://user-images.githubusercontent.com/4989101/172856353-e9ac2ece-fa0c-4536-9c9f-bd112141eebb.mov
@parasharrajat Is this the expected result?
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
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!
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.
Not overdue