Skip to content

[HOLD for payment 2023-11-30] [$500] Cursor position is stuck after emoji on copy pasting text with emoji text in it #29795

Closed

Description

@m-natarajan

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.3.85-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
Expensify/Expensify Issue URL:
Issue reported by: @dhanashree-sawant
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1697546821680559

Action Performed:

  1. Open the app
  2. Open any report
  3. Copy text from any source which has emoji text in middle and not in end eg: Hello How are you :joy test (colon after joy)
  4. Paste in composer and observe that cursor is stuck after emoji instead of displaying it in the end

Expected Result:

App should display cursor at the end of text when we paste any text

Actual Result:

App displays cursor after emoji even when we paste text with emoji text in middle and not in end

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

Android: Native
Android.native.emoji.cursor.position.issue.mp4
Android: mWeb Chrome
Android.chrome.wrong.cursor.position.issue.emoji.mp4
iOS: Native
ios.native.cursor.postion.issue.emoji.mov
iOS: mWeb Safari
ios.safari.cursor.postion.issue.emoji.mov
MacOS: Chrome / Safari
Recording.109.mp4
windows.chrome.cursor.postion.emoji.issue.mp4
MacOS: Desktop
mac.desktop.cursor.position.wrong.emoji.mov

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d23deb324334bf75
  • Upwork Job ID: 1714318176195219456
  • Last Price Increase: 2023-11-07
  • Automatic offers:
    • Ollyws | Reviewer | 27651044
    • barros001 | Contributor | 27651045
    • dhanashree-sawant | Reporter | 27651046

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 17, 2023
  2. melvin-bot commented on Oct 17, 2023

    @melvin-bot

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

  3. changed the title [-]Cursor position is stuck after emoji on copy pasting text with emoji text in it[/-] [+][$500] Cursor position is stuck after emoji on copy pasting text with emoji text in it[/+] on Oct 17, 2023
  4. melvin-bot commented on Oct 17, 2023

    @melvin-bot
  5. melvin-bot commented on Oct 17, 2023

    @melvin-bot

    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
  6. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 17, 2023
  7. melvin-bot commented on Oct 17, 2023

    @melvin-bot

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

  8. ZhenjaHorbach commented on Oct 17, 2023

    @ZhenjaHorbach
    Contributor

    Proposal

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

    Cursor position is stuck after emoji on copy pasting text with emoji text in it

    What is the root cause of that problem?

    Our text input works like this:
    What when we convert text to emoji
    the cursor always appears behind the emoji

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

    react/react-native#22794

    Since, unfortunately, we do not have native support
    Since the proposition was rejected
    We have no way to track when we insert text

    We can try to do it differently
    And add a comparison of the text that is sent to the input and that is stored in the clipboard

    We can update this code

    if (commentValue !== newComment) {
    // Ensure emoji suggestions are hidden even when the selection is not changed (so calculateEmojiSuggestion would not be called).
    if (suggestionsRef.current) {
    suggestionsRef.current.resetSuggestions();
    }
    const remainder = ComposerUtils.getCommonSuffixLength(commentValue, newComment);
    setSelection({
    start: newComment.length - remainder,
    end: newComment.length - remainder,
    });
    }

    Like

                if (commentValue !== newComment) {
                    // Ensure emoji suggestions are hidden even when the selection is not changed (so calculateEmojiSuggestion would not be called).
                    if (suggestionsRef.current) {
                        suggestionsRef.current.resetSuggestions();
                    }
    
                    const remainder = ComposerUtils.getCommonSuffixLength(commentValue, newComment);
    
                    const copiedContent = await Clipboard.getString();
    
                    const isPasted = commentValue.includes(copiedContent); // or using ===
    
                    setSelection({
                        start: newComment.length - (isPasted ? 0 : remainder),
                        end: newComment.length - (isPasted ? 0 : remainder),
                    });
                }
    

    As an alternative Clipboard.getString we can use useClipboard
    https://github.com/react-native-clipboard/clipboard#useclipboard

    What alternative solutions did you explore? (Optional)

    Also, we can try to use onChange
    https://reactnative.dev/docs/textinput#onchange

    with which we can get information about the entered text
    In native event we have a data field

    Screenshot 2023-10-20 at 16 21 43

    which matches the last characters entered

    And if the data contains more than one character
    This means that this text was pasted

    Because if we just write text
    The data will be one symbol long

    And if we have more than one character we will use the same logic as in original proposition

    As a result we can update this line like

                        onChange={(event) => {
                            updateComment(event.nativeEvent.text, true, (event.nativeEvent.data?.length || 0) > 1);
                        }}
    

    Optional

    We can take some of the logic from the original proposition and add

                       const [copiedContent] = useClipboard();
                        onChange={(event) => {
                            const isPasted = event.nativeEvent.text.includes(copiedContent); 
                            updateComment(event.nativeEvent.text, true, ((event.nativeEvent.data?.length || 0) > 1 && isPasted));
                        }}
    

    onChangeText={(commentValue) => updateComment(commentValue, true)}

    This like

    (commentValue, shouldDebounceSaveComment, isPasted) => {

    (commentValue, shouldDebounceSaveComment) => {

    And setSelection like

                    setSelection({
                        start: newComment.length - (isPasted ? 0 : remainder),
                        end: newComment.length - (isPasted ? 0 : remainder),
                    });
    

    setSelection({
    start: newComment.length - remainder,
    end: newComment.length - remainder,
    });

  9. tienifr commented on Oct 18, 2023

    @tienifr
    Contributor

    Proposal

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

    Cursor position is stuck after emoji on copy pasting text with emoji text in it

    What is the root cause of that problem?

    When users paste the text to composer, we're running the following code

    const remainder = ComposerUtils.getCommonSuffixLength(commentValue, newComment);
    setSelection({
    start: newComment.length - remainder,
    end: newComment.length - remainder,
    });
    }

    we set start: newComment.length - remainder is not correct, let's take a look at the above example

    commentValue = Hello How are you :joy:test
    newComment = Hello How are you 😂 test

    -> remainder = 5

    -> the selection always is after emoji

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

    We should not use the remainder here. When users change the input value, we should calculate the actual length change and use this value to update selection

    setSelection({
                        start: selection.start + (newComment.length - commentRef.current.length ),
                        end: selection.end + (newComment.length - commentRef.current.length ),
                    });
    

    Result

    Screen.Recording.2023-10-18.at.16.14.59.mov
  10. CortneyOfstad commented on Oct 18, 2023

    @CortneyOfstad
    Contributor

    @Ollyws any thoughts on the proposals above? TIA!

  11. CortneyOfstad commented on Oct 18, 2023

    @CortneyOfstad
    Contributor

    I am heading OoO until Oct. 25 so reassigning BZ to keep an eye on this while I am gone 👍

  12. 57 remaining items

  13. barros001 commented on Nov 13, 2023

    @barros001
    Contributor

    PR up for review.

  14. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Nov 23, 2023
  15. changed the title [-][$500] Cursor position is stuck after emoji on copy pasting text with emoji text in it[/-] [+][HOLD for payment 2023-11-30] [$500] Cursor position is stuck after emoji on copy pasting text with emoji text in it[/+] on Nov 23, 2023
  16. melvin-bot commented on Nov 23, 2023

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  17. melvin-bot commented on Nov 23, 2023

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.2-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2023-11-30. 🎊

    After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

    • External issue reporter — @dhanashree-sawant paid $50 via Upwork
    • Contributor that fixed the issue — @barros001 paid $500 via Upwork
    • Contributor+ that helped on the issue and/or PR — @Ollyws paid $500 via Upwork

    For reference, here are some details about the assignees on this issue:

  18. melvin-bot commented on Nov 23, 2023

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@Ollyws] The PR that introduced the bug has been identified. Link to the PR:
    • [@Ollyws] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@Ollyws] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@Ollyws] Determine if we should create a regression test for this bug.
    • [@Ollyws] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@CortneyOfstad] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  19. Ollyws commented on Nov 30, 2023

    @Ollyws
    Contributor

    BugZero Checklist:

    • The PR that introduced the bug has been identified. Link to the PR:

    I don't think we can say this is a regression from any PR, It was just only considered that when converting an emoji the cursor should be placed after the emoji regardles if it was typed or pasted.

    • The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:

    N/A

    • A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:

    N/A

    • Determine if we should create a regression test for this bug.

    I don't think a regression test is necessary as we added numerous unit tests that should catch any unwanted changes to the intended behaviour.

  20. CortneyOfstad commented on Dec 1, 2023

    @CortneyOfstad
    Contributor

    @dhanashree-sawant, @Ollyws @barros001 — all have been paid via Upwork and no regression test required, so closing! Thanks all!

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions