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-07-26] [$1000] Cursor jumps to previous word while correcting incorrect emoji #17275

Closed
1 of 6 tasks
kavimuru opened this issue Apr 11, 2023 · 85 comments
Closed
1 of 6 tasks
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kavimuru
Copy link

kavimuru commented Apr 11, 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!


Action Performed:

  1. Open any report.
  2. Try to type any word then an incorrect emoji, try to correct the emoji.
  3. Notice that cursor jump to previous word.

Expected Result

Cursor should stay after the emoji.

Actual Result

Cursor jump to previous word.

Workaround:

unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.2.98-2
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: Any additional supporting documentation

Recording.200.mp4
Screen.Recording.2023-04-11.at.09.40.54.mov

Expensify/Expensify Issue URL:
Issue reported by: @hungvu193
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1681181274203469

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a71f9bea3c846625
  • Upwork Job ID: 1646201349810298880
  • Last Price Increase: 2023-07-11
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 11, 2023
@MelvinBot
Copy link

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

@MelvinBot
Copy link

MelvinBot commented Apr 11, 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

@NicMendonca
Copy link
Contributor

👍 tested on slack and the cursor jumps to the end of the emoji

@NicMendonca NicMendonca added the External Added to denote the issue can be worked on by a contributor label Apr 12, 2023
@melvin-bot melvin-bot bot changed the title Cursor jumps to previous word while correcting incorrect emoji [$1000] Cursor jumps to previous word while correcting incorrect emoji Apr 12, 2023
@MelvinBot
Copy link

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

@MelvinBot
Copy link

Current assignee @NicMendonca is eligible for the External assigner, not assigning anyone new.

@MelvinBot
Copy link

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

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

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

@alitoshmatov
Copy link
Contributor

alitoshmatov commented Apr 12, 2023

Proposal

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

Cursor jumps to previous word while correcting incorrect emoji

What is the root cause of that problem?

The issue is caused here

if (comment !== newComment) {
const remainder = prevState.value.slice(prevState.selection.end).length;
newState.selection = {
start: newComment.length - remainder,
end: newComment.length - remainder,
};
}

Basically this logic is doing this: find the common ending of old and new comment to find where change is happened, and define new selection values to put cursor on the right place.

  • But this logic only works if change happens only in the left side of cursor(before cursor), like: abc :smile:<cursor here> def. It will put cursor in: newComment.end - def.length
  • The logic doesn't work, if changed string is not only in the left side, like: abc :sm<cursor here>ile: def . It will get put put cursor in: newComment.end - ile: def.length . Which is wrong

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

To solve this issue we should improve this logic to get common ending substring of old and new comments. I made a function which checks two strings and returns common ending. Using this function we put cursor right after change in comment(right after emoji inserted).
Old comment: abc :smi<cursor herer>le: def; New comment: abc 😄 def; Cursor should be right before common substring def => abc 😄<cursor here> def

Iether we can change above logic to call my function every time. Or we can apply so that my function is called only in this situation where remainder(prevState.value.slice(prevState.selection.end)) doesn't satisfy condition of being common ending for old and new comment.

I can explain more in details if any questions occur
Result after changes:

cursor.jump.emoji.issue.mov

What alternative solutions did you explore? (Optional)

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Apr 12, 2023

Proposal

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

Cursor start jumps to previous word while correcting incorrect emoji

What is the root cause of that problem?

incorrect calculation for selection after text lenght change (it work fine in other cases but not covered this case).

if (comment !== newComment) {
const remainder = prevState.value.slice(prevState.selection.end).length;
newState.selection = {
start: newComment.length - remainder,
end: newComment.length - remainder,
};
}

it works fine in this case for example if cursor symbolizes as ^
"hello:smile:^ ahmed"
new selection start = new comment lenght (13) - remainder(6) = 7
result will be hello:smile:^ ahmed

but in issue case: this way not work fine, for example:
"hello:smi^le: ahmed"
new selection start = new comment lenght (13) - remainder(9) = 4
result will be hell^o:smile: ahmed

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

change calculate selection start way to cover the issue case, see explanation after code.

if (comment !== newComment) {
    let matchEmoji;
    // eslint-disable-next-line no-cond-assign
    while ((matchEmoji = CONST.REGEX.EMOJI_NAME.exec(comment)) !== null) {
        const checkEmoji = emojisTrie.search(matchEmoji[0].slice(1, -1));
        if (checkEmoji && checkEmoji.metaData.code) {
            newState.selection = {
                start: matchEmoji.index + 1,
                end: matchEmoji.index + 1,
            };
            break;
        }
    }
}

new selection start should be after emoji which mean prev comment value get index of imoji text + 1
without deponding on current cursor.

"hello:smile:^ ahmed" newSelection start = index of imoji text(5) + 1 = 6;
"hello:smi^le: ahmed" newSelection start = index of imoji text(5) + 1 = 6;
"hello:s^mile: ahmed" newSelection start = index of imoji text(5) + 1 = 6;
this way will cover all cases because it not depond on current cursor.

What alternative solutions did you explore? (Optional)

Same as solution above, but use match instead exec.
This fix is similar to EmojiUtils.replaceEmojis here.

  if (comment !== newComment) {
      const emojiData = comment.match(CONST.REGEX.EMOJI_NAME);
      if (_.isArray(emojiData) && emojiData.length > 0) {
          for (let i = 0; i < emojiData.length; i++) {
              const name = emojiData[i].slice(1, -1); // remove start and end ":"
              const checkEmoji = emojisTrie.search(name);
              if (checkEmoji && checkEmoji.metaData.code) {
                  newState.selection = {
                      start: comment.indexOf(emojiData[i]) + 1,
                      end: comment.indexOf(emojiData[i]) + 1,
                  };
              }
          }
      }
  }

We should use loop to skip match :non-emoji-value:
optional we can also fix edge case when copy past before :smile: after in this case, the cursor will set after emoji not at the end of text before :smile:^ after.
We need to confirm is the cursor is inside the emoji text

if (checkEmoji && checkEmoji.metaData.code) {
    const index = comment.indexOf(emojiData[i]);
    if (prevState.selection.end >= index && prevState.selection.end <= (index + emojiData[i].length)){
        newState.selection = {
            start: index + 1,
            end: index + 1,
        };
    }
}

@alitoshmatov
Copy link
Contributor

Updated broken video - #17275 (comment)

@parasharrajat
Copy link
Member

@alitoshmatov Do you mind explaining the logic of that function in your proposal?

@alitoshmatov
Copy link
Contributor

alitoshmatov commented Apr 12, 2023

@parasharrajat Yes, basically it is a utility function which takes two string inputs and returns common ending substring

commonEndingSubstring("abcdxyz", "123456xyz"); // "xyz"
commonEndingSubstring("Hello :smile: world", "Hello 😄 world"); //" world"

@alitoshmatov
Copy link
Contributor

@ahmedGaber93 #17275 (comment) your solution is not working. When new emoji is inserted, It is confusing and putting cursor to a string with columns in two side which is not emoji:non-emoji-value:.

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Apr 12, 2023

@alitoshmatov thanks for your comment, please tell me what you try to type and what's the result displayed for you?

@alitoshmatov
Copy link
Contributor

@ahmedGaber93 cursor - ^
I typed: Hello :notemoji: world :smile:^ Resulted: Hello :^notemoji: world 😄

I am not sure right now where the cursor jumped, but it was definitely around :notemoji:

@ahmedGaber93
Copy link
Contributor

ahmedGaber93 commented Apr 12, 2023

@alitoshmatov thanks fot testing my proposal.
we can pass it by checking if the match text is emoji or not by emojisTrie

if (comment !== newComment) {
    let matchEmoji;
    // eslint-disable-next-line no-cond-assign
    while ((matchEmoji = CONST.REGEX.EMOJI_NAME.exec(comment)) !== null) {
        const checkEmoji = emojisTrie.search(matchEmoji[0].slice(1, -1));
        if (checkEmoji && checkEmoji.metaData.code) {
            newState.selection = {
                start: matchEmoji.index + 1,
                end: matchEmoji.index + 1,
            };
            break;
        }
    }
}

try it now.

@bernhardoj
Copy link
Contributor

Dupe of this #13066

@melvin-bot melvin-bot bot added the Overdue label Apr 17, 2023
@NicMendonca
Copy link
Contributor

@parasharrajat do you think this is a proper dupe? ☝️

@melvin-bot melvin-bot bot removed the Overdue label Apr 17, 2023
@parasharrajat
Copy link
Member

Checking...

@MelvinBot
Copy link

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 12, 2023

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

@MariaHCD
Copy link
Contributor

Nice! @alitoshmatov's proposal looks good to me too.

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

melvin-bot bot commented Jul 13, 2023

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

Upwork job

@melvin-bot
Copy link

melvin-bot bot commented Jul 13, 2023

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

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 📖

@melvin-bot
Copy link

melvin-bot bot commented Jul 13, 2023

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

Upwork job

@alitoshmatov
Copy link
Contributor

PR is ready - #22827

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels Jul 19, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Cursor jumps to previous word while correcting incorrect emoji [HOLD for payment 2023-07-26] [$1000] Cursor jumps to previous word while correcting incorrect emoji Jul 19, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jul 19, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 19, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 19, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.42-26 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-07-26. 🎊

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
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Jul 19, 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:

  • [@aimane-chnaif] The PR that introduced the bug has been identified. Link to the PR:
  • [@aimane-chnaif] 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:
  • [@aimane-chnaif] 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:
  • [@aimane-chnaif] Determine if we should create a regression test for this bug.
  • [@aimane-chnaif] 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.
  • [@NicMendonca] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Jul 25, 2023
@NicMendonca
Copy link
Contributor

@hungvu193 - reporting: $250
@alitoshmatov - C: $1500
@aimane-chnaif C+: $1500

@NicMendonca
Copy link
Contributor

^ all 3 of have been paid 🎉

@NicMendonca
Copy link
Contributor

@aimane-chnaif just a reminder on the BZ checklist: #17275 (comment)

@aimane-chnaif
Copy link
Contributor

  • The PR that introduced the bug has been identified. Link to the PR: Fix cursor position when adding emoji #12632
  • 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: https://github.com/Expensify/App/pull/12632/files#r1278643811
  • 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.
  • 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.

Regression Test Proposal:

  1. Go to any chat
  2. Type any text which includes emoji name without space (i.e. hello:smhile:)
  3. Put your cursor in the middle of text (between h and i)
  4. Click backspace to remove wrong character h and complete emoji name :smile:
  5. Verify that emoji name is replaced with emoji itself and cursor is placed right after emoji

@NicMendonca
Copy link
Contributor

Thank you! All set here!

Payment summary here: #17275 (comment)

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 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests