Skip to content
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-11-30] [$500] Cursor position is stuck after emoji on copy pasting text with emoji text in it #29795

Closed
5 of 6 tasks
m-natarajan opened this issue Oct 17, 2023 · 44 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor

Comments

@m-natarajan
Copy link

m-natarajan commented Oct 17, 2023

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
@m-natarajan m-natarajan added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 17, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

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

@melvin-bot melvin-bot bot 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 Oct 17, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01d23deb324334bf75

@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 17, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

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

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Oct 17, 2023

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?

facebook/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,
});

@tienifr
Copy link
Contributor

tienifr commented Oct 18, 2023

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

@CortneyOfstad
Copy link
Contributor

@Ollyws any thoughts on the proposals above? TIA!

@CortneyOfstad
Copy link
Contributor

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

@CortneyOfstad CortneyOfstad removed their assignment Oct 18, 2023
@CortneyOfstad CortneyOfstad added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Oct 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 18, 2023

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

@CortneyOfstad CortneyOfstad self-assigned this Oct 18, 2023
@Expensify Expensify deleted a comment from melvin-bot bot Oct 20, 2023
@johncschuster
Copy link
Contributor

@Ollyws, what are your thoughts on the proposals above?

@Ollyws
Copy link
Contributor

Ollyws commented Oct 20, 2023

Thanks for the proposals everyone.

@ZhenjaHorbach So what you're saying is there is no way we can listen for paste events, correct? The problem I can see with your proposal is that if a user were to type the same text as is on their clipboard isPasted would be true.

@tienifr Unfortunately your proposal would re-create #17275

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Oct 20, 2023

Thanks for the proposals everyone.

@ZhenjaHorbach So what you're saying is there is no way we can listen for paste events, correct? The problem I can see with your proposal is that if a user were to type the same text as is on their clipboard isPasted would be true.

@tienifr Unfortunately your proposal would re-create #17275

Yes, unfortunately, I haven’t found an adequate way to catch paste events for text input

We have Something more or less suitable for the web
https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event

But for mobile apps i can't find
Only if we don’t want to patch the RN and add a proposal that was rejected about onPaste

But yes, the disadvantage of my proposal is that there are rare cases when the current text may be the same as the text stored on the clipboard
But the likelihood of such an event is, in my opinion, extremely low on real work

But I add alternative proposition
#29795 (comment)
I think this solution will be without the disadvantages of the original )

@melvin-bot melvin-bot bot added the Overdue label Oct 23, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Oct 23, 2023

Still open for more proposals on this one...

@melvin-bot melvin-bot bot removed the Overdue label Oct 23, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 24, 2023

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

@melvin-bot melvin-bot bot added the Overdue label Oct 25, 2023
@melvin-bot melvin-bot bot added the Overdue label Nov 13, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Nov 13, 2023

Will have a look at this one today.

@melvin-bot melvin-bot bot removed the Overdue label Nov 13, 2023
@Ollyws
Copy link
Contributor

Ollyws commented Nov 13, 2023

I like @barros001's general approach and it seems to resolve all of the issues we previously mentioned.

There is one small issue where if you paste innertext :joy: innertext between two peices of text, the cursor will remain after the emoji rather than the second innertext, but that can be ironed out in the PR and I think we have enough here to move things forward.

So let's go with @barros001's proposal.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Nov 13, 2023

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

@barros001
Copy link
Contributor

@Ollyws thanks for reviewing my proposal.

There` is one small issue where if you paste innertext 😂 innertext between two peices of text, the cursor will remain after the emoji rather than the second innertext, but that can be ironed out in the PR and I think we have enough here to move things forward.

I just tested this scenario and it works as expected, see video below. Maybe this got fixed along the way as I was working on the proposal. But as you said, any issues that arises we'll iron out in the PR.

Screen.Recording.2023-11-13.at.10.43.14.AM.mov

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 13, 2023
Copy link

melvin-bot bot commented Nov 13, 2023

📣 @Ollyws 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Nov 13, 2023

📣 @barros001 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

Copy link

melvin-bot bot commented Nov 13, 2023

📣 @dhanashree-sawant 🎉 An offer has been automatically sent to your Upwork account for the Reporter role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Nov 13, 2023
@barros001
Copy link
Contributor

PR up for review.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Nov 23, 2023
@melvin-bot melvin-bot bot 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 Nov 23, 2023
Copy link

melvin-bot bot commented Nov 23, 2023

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Nov 23, 2023
Copy link

melvin-bot bot commented Nov 23, 2023

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:

Copy link

melvin-bot bot commented Nov 23, 2023

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:

@Ollyws
Copy link
Contributor

Ollyws commented Nov 30, 2023

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.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Nov 30, 2023
@CortneyOfstad
Copy link
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
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

9 participants