Skip to content

[$250] Markdown - Space in the Code Block is removed after Manually copying and pasting #43331

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.80-16
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4606901
Email or phone of affected tester (no customers): dave0123seife+admin@gmail.com
Issue reported by: Applause - Internal Team

Action Performed:

  1. Navigate to a 1:1 chat
  2. Send a message with a Code block. Make the code block a multiline with an extra line between the markdown and text.
  3. Manually Copy and paste the message with the code block

Expected Result:

The correct markdown format is pasted

Actual Result:

The markdown format removes the line space

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6505942_1717827443315.CodeBloke_Copy.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~014e40385be5828d12
  • Upwork Job ID: 1802910270409896448
  • Last Price Increase: 2024-07-26
Issue OwnerCurrent Issue Owner: @eVoloshchak

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 8, 2024
  2. melvin-bot commented on Jun 8, 2024

    @melvin-bot

    Triggered auto assignment to @MitchExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. lanitochka17 commented on Jun 8, 2024

    @lanitochka17
    Author

    @MitchExpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

  4. lanitochka17 commented on Jun 8, 2024

    @lanitochka17
    Author

    We think that this bug might be related to #vip-vsp

  5. kpadmanabhan commented on Jun 10, 2024

    @kpadmanabhan

    @lanitochka17 : this is related to #39971
    This is on hold as PR for this is blocked due to another related issue.
    Awaiting update.
    CC: @jayeshmangwani / @roryabraham

  6. jayeshmangwani commented on Jun 10, 2024

    @jayeshmangwani
    Contributor

    @kpadmanabhan Are you sure this is related to #39971 ?

    I have tested again after applied the solution from the PR #42892 and it doesn't solve the current issue, can you please link between this issue and other one how they are related ?

  7. MitchExpensify commented on Jun 11, 2024

    @MitchExpensify
    Contributor

    Not overdue, ball is in @kpadmanabhan 's court

  8. kpadmanabhan commented on Jun 13, 2024

    @kpadmanabhan

    @MitchExpensify / @jayeshmangwani : sorry for late response. On it now.

    In main HEAD, copying using Copy to Clipboard menu item works fine with complete text from the code block. But using CTRL+C copies only the current text without the newline inside the code.

    Recording.2024-06-14.011634.mp4

    The fix for #39971 will not solve this issue. The text is already trimmed while copying to clipboard.
    Working on this. Will update soon here.

  9. kpadmanabhan commented on Jun 14, 2024

    @kpadmanabhan

    Proposal

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

    Pasted code block trimming trailing newline characters.

    What is the root cause of that problem?

    Two concerns from the initially reported problem.

    1. From the initial video recording in bug description, the text is NOT selected in full. Only 1 trailing newline is selected by selecting the text. To select the complete code block, one will need to go till end of code block till end of message. The same is demonstrated in the video recording further below.

    2. Send button is not enabled because the trailing CR LF (\n) while pasting is not considered in selection and hence not considered in the range length.

    src\hooks\useHtmlPaste\index.ts

    const insertAtCaret = (target: HTMLElement, text: string) => {
            . . . 
            // Move caret to the end of the newly inserted text node.
            range.setStart(node, node.length);
            range.setEnd(node, node.length);
            . . . 
    

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

    Check if this is a code block or is text having trailing newline, then calculate range accordingly with offset.

    src\hooks\useHtmlPaste\index.ts

    const insertAtCaret = (target: HTMLElement, text: string) => {
        . . . 
    
            // Move caret to the end of the newly inserted text node.
            // Text with newline at end or code block that ends with ``` 
            // These lines must be pasted in full and "Send" button enabled.
            // length reduced by an offset of 1 character to accommodate the trailing \n (CR LF) 
            const offset = text.trimEnd().endsWith('```') || text.endsWith('\n') 
                ? node.length - 1 : node.length;
            range.setStart(node, offset);
            range.setEnd(node, offset);
        . . . 
    

    This makes sure that the correctly selected code block is pasted in full and send button is enabled.

    Recording.2024-06-14.132257.mp4
    Recording.2024-06-14.133756.mp4

    What alternative solutions did you explore? (Optional)

    N.A.

  10. kpadmanabhan commented on Jun 14, 2024

    @kpadmanabhan

    @MitchExpensify / @jayeshmangwani / @lanitochka17 : if you think this solves the issue reported, please mark this bug external and kindly assign.

  11. 60 remaining items

  12. melvin-bot commented on Jul 22, 2024

    @melvin-bot

    @eVoloshchak, @adelekennedy Whoops! This issue is 2 days overdue. Let's get this updated quick!

  13. adelekennedy commented on Jul 23, 2024

    @adelekennedy
    Contributor

    @eVoloshchak what are the next steps here?

  14. melvin-bot commented on Jul 26, 2024

    @melvin-bot

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

  15. kpadmanabhan commented on Jul 27, 2024

    @kpadmanabhan

    In latest main HEAD I still see these behaviour as explained and shown in my proposal.

    Also pasting of text from "Copy to clipboard" context menu is ending up placing the cursor at end of code block.
    @eVoloshchak : the issue you mentioned is not reproducible at my side.

    @adelekennedy : the core issue seems to be fixed. however there are regressions w.r.t copying using mouse / trackpad click and drag. if you do nmot click and drag till outside of the message (not just till outside code block), then this works fine in main HEAD.

    Please let me know if you need further details.

  16. melvin-bot commented on Jul 29, 2024

    @melvin-bot

    @eVoloshchak, @adelekennedy Huh... This is 4 days overdue. Who can take care of this?

  17. kpadmanabhan commented on Jul 30, 2024

    @kpadmanabhan

    @eVoloshchak / @adelekennedy : shall i pick this up for fixing? key problem here is the selection of text from code block.
    fix will be that in case selection is till end of message and the data from clipboardv endswith code block, then add extra newline if selected till end.

    please suggest if i may proceed with the fix.

  18. mallenexpensify commented on Jul 30, 2024

    @mallenexpensify
    Contributor

    @eVoloshchak 👀 above plz

  19. melvin-bot commented on Jul 31, 2024

    @melvin-bot

    @eVoloshchak, @adelekennedy 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  20. eVoloshchak commented on Aug 1, 2024

    @eVoloshchak
    Contributor

    I'm not sure if this is worth fixing, it's not a bug with the app itself, but rather the way OS handles text selection.
    I can observe the same behavior here on GitHub

    Screen.Recording.2024-08-01.at.18.42.32.mov

    @mallenexpensify, @adelekennedy, what are your thoughts?

  21. adelekennedy commented on Aug 1, 2024

    @adelekennedy
    Contributor

    I'd move to close it in that case, it's low priority any way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions