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

Web - Composer - Cursor positioned at the start if pasting text which contains a new line #42892

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

moonstar-95515
Copy link
Contributor

@moonstar-95515 moonstar-95515 commented May 31, 2024

Details

Web - Composer - Cursor positioned at the start if pasting text which contains a new line

Fixed Issues

$ #42216
PROPOSAL: #42216 (comment)

Tests

  1. Navigate to staging.new.expensify.com
  2. Open a chat and type a one line text and create an empty new line
  3. Select all using keyboard ctrl + A and cut the text
  4. Paste it inside the compose box

Verify the cursor is positioned at the end of the pasted text

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Navigate to staging.new.expensify.com
  2. Open a chat and type a one line text and create an empty new line
  3. Select all using keyboard ctrl + A and cut the text
  4. Paste it inside the compose box

Verify the cursor is positioned at the end of the pasted text

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android.mp4
Android: mWeb Chrome
android.-chrome.mp4
iOS: Native
ios-native.mp4
iOS: mWeb Safari
bandicam.2024-06-11.17-34-50-999.mp4
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
bandicam.2024-06-11.17-03-26-854.mp4

@moonstar-95515 moonstar-95515 requested a review from a team as a code owner May 31, 2024 03:15
@melvin-bot melvin-bot bot removed the request for review from a team May 31, 2024 03:15
Copy link

melvin-bot bot commented May 31, 2024

@eVoloshchak Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested a review from eVoloshchak May 31, 2024 03:15
Copy link
Contributor

github-actions bot commented May 31, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@moonstar-95515
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@@ -16,8 +16,9 @@ const insertAtCaret = (target: HTMLElement, text: string) => {
range.insertNode(node);

// Move caret to the end of the newly inserted text node.
range.setStart(node, node.length);
range.setEnd(node, node.length);
const offset = (text.length && text[text.length - 1] === '\n' ? node.length - 1 : node.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const offset = (text.length && text[text.length - 1] === '\n' ? node.length - 1 : node.length);
const offset = text?.endsWith('\n') ? node.length - 1 : node.length;

@@ -16,8 +16,9 @@ const insertAtCaret = (target: HTMLElement, text: string) => {
range.insertNode(node);

// Move caret to the end of the newly inserted text node.
range.setStart(node, node.length);
range.setEnd(node, node.length);
const offset = (text.length && text[text.length - 1] === '\n' ? node.length - 1 : node.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining why this logic is needed and include a link to the issue?

@moonstar-95515
Copy link
Contributor Author

Hi, @eVoloshchak
I've pushed updates.

@@ -16,8 +16,12 @@ const insertAtCaret = (target: HTMLElement, text: string) => {
range.insertNode(node);

// Move caret to the end of the newly inserted text node.
range.setStart(node, node.length);
range.setEnd(node, node.length);
// we have to set offset as `node.length - 1` when text has empty line at the end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// we have to set offset as `node.length - 1` when text has empty line at the end
// Correctly calculate text length since newline character does not create a new line in HTML
// https://github.com/Expensify/App/issues/42216

@eVoloshchak
Copy link
Contributor

@moonstar-95515, looks awesome, there are a couple of steps left to finish up the author checklist:

  • include screen recordings for all of the platforms
  • include the final step in Tests section: "Verify the cursor is positioned at the end of the pasted text"
  • Include QA Steps (should be the same as regular Tests)

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak
I tried to login in local server. But it constantly get this error. Is it working fine on your side?
image

@eVoloshchak
Copy link
Contributor

@moonstar-95515, works fine for me (a little slow though)
Try pulling the latest main and clearing cookies and site data

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak
Sorry for delay but I still have problem with login.

@eVoloshchak
Copy link
Contributor

@moonstar-95515, try doing this

Screen.Recording.2024-06-10.at.19.01.27.mov

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak
Thank you. I tried this but it doesn't help.

@eVoloshchak
Copy link
Contributor

@moonstar-95515, did you pull the latest changes from main?
It should be working, just verified

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak
Thank you. I merged latest main to my working branch and it works.
I've uploaded videos for ios and desktop.

@eVoloshchak
Copy link
Contributor

eVoloshchak commented Jun 11, 2024

I merged latest main to my working branch and it works

@moonstar-95515, could you push this commit so I can test this PR with the latest changes?
Also, screen recordings for Android: Native and Android: mWeb Chrome are missing

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak
I've pushed updates.
For android, I have some problems as well. Is there any possibility to go further with current status?
Thank you in advance.

@eVoloshchak
Copy link
Contributor

Is there any possibility to go further with current status?

It is much preferred if we both double-check all of the platforms, let's try to get this working on Android for you. What problem are you having?

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak

It is much preferred if we both double-check all of the platform

Thank you I got it.
But unfortunately, my MacOS is borken unexpectedly and it seems it's difficult to make it work soon.
Sorry for inconvenience.

@eVoloshchak
Copy link
Contributor

@moonstar-95515, check out our TESTING_MACOS_AND_IOS.md guide

@kpadmanabhan
Copy link

I was working on this issue initially. When my PR was in progress, proposal for this PR was picked up. Based on @jayeshmangwani comment, ideally this PR and proposal should have been withdrawn. My PR is on HOLD for quite some days now.

However, as @moonstar-95515 also suggested a good alternative solution for the issue, but now that they are stuck with continuing, I am ok with taking this forward in whichever way Expensify sees it logical as per code of conduct.

@jayeshmangwani / @roryabraham / @eVoloshchak / @slafortune / @mallenexpensify : kindly suggest way forward.

@moonstar-95515
Copy link
Contributor Author

I'm sorry that I have some issues with recording test video but I'm still working on this issue.

@kpadmanabhan
I really appreciate your effort in your PR but I think your PR is hold due to regression.
I've almost completed this PR.

@kpadmanabhan
Copy link

@moonstar-95515 : thanks for the update. Will await completion of your PR.

@eVoloshchak
Copy link
Contributor

@moonstar-95515, were you able to get your development environment working?

@moonstar-95515
Copy link
Contributor Author

@eVoloshchak
Sorry for delay.
I'm building android environment.
But I think I tried every solution but I was not able to run emulator.
Is it possible to run android version on VM?

@eVoloshchak
Copy link
Contributor

Is it possible to run android version on VM?

@moonstar-95515, it is possible
Also, TESTING_MACOS_AND_IOS.md tells how you can use a macOS instance (real mac that you use through remote desktop)

Could you share which problems you're having exactly?

@moonstar-95515
Copy link
Contributor Author

Thank you. @eVoloshchak
I'm not able to run android emulator on VMware.

@jayeshmangwani
Copy link
Contributor

But I think I tried every solution but I was not able to run emulator.

@moonstar-95515 What error did you encounter?

@mallenexpensify
Copy link
Contributor

@moonstar-95515 per CONTRIBUTING.md, it's a requirement to be able to test on Android

Make sure you can test on all platforms
Expensify requires that you can test the app on iOS, MacOS, Android, Web, and mWeb.

This PR has been open for over a month, I'd love to get it wrapped ASAP

@moonstar-95515
Copy link
Contributor Author

Thank you everybody.
Finally, I was able to build android on my new Mac.

@eVoloshchak
I've uploaded all videos. Please check.

@eVoloshchak
Copy link
Contributor

@moonstar-95515, looks like this is already resolved on staging, could you double-check please?

Screen.Recording.2024-07-08.at.00.06.04.mov

@mallenexpensify
Copy link
Contributor

Also confirming I am unable to reproduce on staging.new.expensify.com . Anyone know what PR might have fixed this?

@jayeshmangwani
Copy link
Contributor

@eVoloshchak @mallenexpensify I tested this today, and the issue is happening again, even though it was working fine two days ago. It is working fine in production, but the issue is happening on staging

@mallenexpensify
Copy link
Contributor

I'm experiencing a different bug on staging (and not production), when I paste text with a blank line underneath, it shows being greyed out and I'm not able to type 'return' to send the message

2024-07-11_17-28-34.mp4

@kpadmanabhan
Copy link

I'm experiencing a different bug on staging (and not production), when I paste text with a blank line underneath, it shows being greyed out and I'm not able to type 'return' to send the message

I tested on main HEAD without applying any local fixes. the core problem is fixed.

@jayeshmangwani, the approach taken here is to trim off the trailing new-line. This was my first proposal, which is on hold for almost 2 months now. But these changes from someone else has reached production bypassing all regressions. Referring to this.

@eVoloshchak : code in main HEAD trims off newlines from inside code block irrespective of how much ever you copy. refererring to this.

@mallenexpensify : due to extra long waiting times with issues on HOLD, I see that others are fixing code in the same area and the same is merged to main with known regressions (due to which my PR was put on hold). Kin dly suggest how to proceed here.

@mallenexpensify
Copy link
Contributor

@kpadmanabhan commented on the issue you're assigned, can you follow up there plz? thx
#39971 (comment)

@eVoloshchak
Copy link
Contributor

@moonstar-95515, since the issue was already resolved, could you close this PR please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants