-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[HOLD for payment 2023-04-20] [$1000] Inconsistent link copy between manual copy and "Copy to Clipboard" #16525
Comments
Triggered auto assignment to @anmurali ( |
Bug0 Triage Checklist (Main S/O)
|
@anmurali Whoops! This issue is 2 days overdue. Let's get this updated quick! |
Job added to Upwork: https://www.upwork.com/jobs/~01ee21b7899295084b |
Current assignee @anmurali is eligible for the External assigner, not assigning anyone new. |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Santhosh-Sellavel ( |
Triggered auto assignment to @luacmartins ( |
Created a job for external contributors. |
ProposalPlease re-state the problem that we are trying to solve in this issue.While link copied with "Copy to Clipboard" retains its hyperlink format, link copied manually doesn't retain it and just copies regular text (without link) What is the root cause of that problem?The root cause of the problem is that when you select text the browser selects only text. Copy button in menu copies the underlying markdown using ExpesniMark object to convert html to text or markdown. What changes do you think we should make in order to solve the problem?We have a keyboard listener for copy to clipboard keys in a separate component here: App/src/components/CopySelectionHelper.js Line 12 in 2398744
and this component is mounted in ReportActionView:
It converts html to markdown and doesn't do it when you have only link in a post App/src/components/CopySelectionHelper.js Line 36 in 2398744
we could alter this to capture single links: Clipboard.setString(parser.htmlToMarkdown(parser.htmlToMarkdown(parser.replace(selection,{filterRules:['autolink']})))); (this is weird, we'd better write another rule in ExpensiMark) I think we shouldn't alter "Copy URL" and "Copy" behaviour as they are intended. App/src/pages/home/report/ContextMenu/ContextMenuActions.js Lines 113 to 121 in 2398744
What alternative solutions did you explore? (Optional)Honestly, I think it isn't right to copy to clipboard something different than you see. So maybe we should alter the "Copy" function here:
change to Clipboard.setString(parser.htmlToText(content));
|
ProposalPlease re-state the problem that we are trying to solve in this issue.Link copied manually isn't retain it and just pasted regular text (without link) What is the root cause of that problem?Because when user select a text that starts and ends within a HTML tag, in the method SelectionScraper.getHTMLOfSelection, the window.getSelection() API only returns content of selection, which is string. It doesn't know that there is an anchor tag outside. What changes do you think we should make in order to solve the problem?We can add more code in this line so that if the selection starts and ends within same text node, we do more check if it's textContent same as parentNode's textContent, we assume user selected whole content in the parent node => use the parentNode instead of itself => it will ensure we can copy the anchor tag so that we can parse it as an url later Sample code how does it look like: const parentNode = range.commonAncestorContainer.parentNode;
if (parentNode.textContent === clonedSelection.textContent) {
clonedSelection = range.createContextualFragment(parentNode.outerHTML);
}
node = parentNode.closest(`[${tagAttribute}]`); |
ProposalPlease re-state the problem that we are trying to solve in this issue.When the link is copied manually it loses the hyperlink ( and appears as regular text) , however it retains it when copied with "Copy to Clipboard" What is the root cause of that problem?The main issue stems from the fact that when text is selected, the browser only selects the text itself. However, the "Copy" button in the menu copies the markdown that underlies the selected HTML, using the ExpesniMark object to convert it to either text or markdown format. The right-click menu is designed to have different options that are relevant to the content of the post. Therefore, the "Copy URL to clipboard" action is separate from the "Copy to clipboard" action. Additionally, if there is both a link and text in a post, the right-click menu will differ depending on which part of the post is selected (either the link or the text). What changes do you think we should make in order to solve the problem?Select the link element that contains the URL to be copied, and then add an event listener to the "Copy to Clipboard" button. When the button is clicked, create a new temporary input element, set its value to the URL of the link element, and add it to the document. Then select the contents of the temporary input element and execute the "copy" command to copy the URL to the clipboard. Finally, Remove the temporary input element from the document. Also add an event listener to the link element itself, which handles manual copying. When the link is clicked, use the navigator.clipboard.writeText() method to copy the URL to the clipboard directly. What alternative solutions did you explore? (Optional)Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
📣 @dianaferreira1! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Format:
|
✅ Contributor details stored successfully. Thank you for contributing to Expensify! |
Contributor details |
|
Contributor details |
|
ProposalPlease re-state the problem that we are trying to solve in this issue.When we copy the link manually (ctrl+c) and paste it to composer, the formatting/markdown is lost. What is the root cause of that problem?We should understand first what happen when we copy a chat manually. Copying a chat manually will select the HTML from what we currently selecting (the blue highlight). App/src/libs/SelectionScraper/index.js Lines 133 to 139 in 2f922c4
For example, if the chat is a bold message, the selected HTML will be How can it's converted to strong and also know which HTML to select? It's all thanks to App/src/libs/SelectionScraper/index.js Lines 63 to 67 in 2f922c4
And then later converted to it's Now, why it does not work for anchor tag? The App/src/components/HTMLEngineProvider/HTMLRenderers/AnchorRenderer.js Lines 86 to 105 in 2f922c4
This makes the So, when we copy a link, this is what we get
NOTE: There are some tag that uses custom renderer too (e.g., code, pre) that still works because both of them use the What changes do you think we should make in order to solve the problem?Because we use a custom renderer, we need to set the App/src/components/AnchorForCommentsOnly/BaseAnchorForCommentsOnly.js Lines 69 to 82 in 2f922c4
|
@bernhardoj proposal here seems like a right approach to me, let me know your thoughts please, thanks! |
@Santhosh-Sellavel there is a behavior that you might need to consider with @bernhardoj proposal above. It's if we only select a part of link, For example: only select |
Just waiting on tests |
Is this waiting for me or @anmurali |
I see these items unchecked in the checklist:
|
I'm sure the applause team is aware of the ways to copy the messages keyboard method. Regression steps:
👍 or 👎 cc: @luacmartins |
@Santhosh-Sellavel test steps make sense! |
@anmurali can we add these test steps to TestRail? |
waiting on tests |
Paid |
Hi there, I am sorry to asking to this closed issue, but it seems that I, as the issue reporter, hasn't got the offer and also hasn't been paid. Is it okay to ask for help on this matter? Thanks in advance. |
@kerupuksambel could you please apply here on Upwork, so we can pay you? |
@kadiealexander I am sorry, but it seems that I can't apply there due to 403 error in Upwork. Could you please send me a publicly available offer for me to apply at or accept? Thanks beforehand |
Could you please try this one? |
@kadiealexander Thank you for the offer, I have applied to the job. |
@kerupuksambel I've sent an offer, please accept and I'll issue payment :) |
@kadiealexander Thanks! Offer has been accepted now. |
Thanks! All paid :) |
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Action Performed:
Examine the difference
Expected Result:
All three copying methods retains the hyperlink format when copied in the chat textbox
Actual Result:
While link copied with "Copy to Clipboard" retains its hyperlink format, link copied manually isn't retain it and just pasted regular text (without link)
Workaround:
unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Version Number: 1.2.89-0
Reproducible in staging?: y
Reproducible in production?: y
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:
Link.Copy.mp4
Recording.59.mp4
Expensify/Expensify Issue URL:
Issue reported by: @kerupuksambel
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1679808047035209
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: