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

Replace double newlines with a single newline #13739

Merged
merged 8 commits into from
Jan 10, 2023

Conversation

tgolen
Copy link
Contributor

@tgolen tgolen commented Dec 20, 2022

Fixed Issues

$ #12769

Tests

Use the following text for the test (it has 4 newlines):

I'm around if you are and wanna hop on a call https://meet.google.com/yjx-maas-pku



Nothing specific in mind

Web/Desktop

  1. Copy that text
  2. Paste it normally into the chat composer using ctrl+v
  3. Verify that it still contains the 4 newlines
  4. Paste it without formatting into the chat composer user ctrl+shift+v
  5. Verify that it still contains the 4 newlines and no more
  6. Send the message
  7. Copy the previous message by right-clicking the message and select copy it to clipboard
  8. Repeat steps 2-5
  9. Copy the message by clicking the copy to clipboard in the hover menu
  10. Repeat steps 2-5
  11. Copy the message by highlighting all the text of the comment, right-click the message > select copy to clipboard
  12. Repeat steps 2-5
  13. Copy text inside the composer input that contains newlines by using ctrl+c
  14. Repeat steps 2-5
  15. Copy text inside the composer input that contains newlines by using ctrl+x
  16. Repeat steps 2-5

Native and mobile web

Native platforms do not have a paste without formatting feature, so just do basic regression testing to ensure pasting functions normally

  1. Copy that text
  2. Paste it normally into the chat composer
  3. Verify that it still contains the 4 newlines
  • Verify that no errors appear in the JS console

Offline tests

n/a this feature doesn't change or is impacted by offline mode

QA Steps

Same as above

  • 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 / Chrome
    • iOS / native
    • iOS / 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 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
    • 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 correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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(themeColors.componentBG)
  • 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
2022-12-20_14-06-50.mp4
Mobile Web - Chrome
2022-12-20_14-08-19.mp4
Mobile Web - Safari
2022-12-20_14-11-50.mp4
Desktop
2022-12-20_14-10-15.mp4
iOS
2022-12-20_14-11-13.mp4
Android
2022-12-20_14-09-15.mp4

@tgolen tgolen self-assigned this Dec 20, 2022
@tgolen tgolen requested a review from a team as a code owner December 20, 2022 21:18
@melvin-bot melvin-bot bot requested review from robertjchen and sobitneupane and removed request for a team December 20, 2022 21:18
@melvin-bot
Copy link

melvin-bot bot commented Dec 20, 2022

@sobitneupane @robertjchen One of you needs to 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]

@@ -265,7 +265,9 @@ class Composer extends React.Component {
return;
}

const plainText = event.clipboardData.getData('text/plain');
// The regex replace is there because when doing a "paste without formatting", there are extra line breaks added to the content (I do not know why). To fix the problem, anytime
// there is a double set of newline characters, they are replaced with a single newline. This preserves the same number of newlines between pasting with and without formatting.
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
// there is a double set of newline characters, they are replaced with a single newline. This preserves the same number of newlines between pasting with and without formatting.
// there is a double set of newline characters, they are replaced with a single newline. This preserves the same number of new lines between pasting with and without formatting.

@sobitneupane
Copy link
Contributor

Testing ....

Copy link
Contributor

@sobitneupane sobitneupane left a comment

Choose a reason for hiding this comment

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

If we select the text and copy it with Ctl+C, it works as expected. But if we copy the text with "Copy to Clipboard" option from context menu and paste with Ctrl+Shift+V, new lines get removed.

Steps to reproduce:

  1. Right click on the sent message and select Copy to clipboard
  2. Paste the message with Ctrl+Shift+V
  3. Expected new lines get removed.
Screen.Recording.2022-12-21.at.20.34.23.mov

@tgolen
Copy link
Contributor Author

tgolen commented Dec 28, 2022

Thanks for reporting that! I've updated this branch so that the context menu and CTRL+c will have consistent behaviors for browsers.

@sobitneupane
Copy link
Contributor

sobitneupane commented Dec 29, 2022

@tgolen When I copy the text from Github and paste it with "Ctrl+Shift+V", newlines get removed.

Steps to Reproduce:

  1. Copy the following text.
I'm around if you are and wanna hop on a call https://meet.google.com/yjx-maas-pku



Nothing specific in mind
  1. Paste it with Ctrl+Shift+V in new expensify.
Screen.Recording.2022-12-29.at.23.37.05.mov

@sobitneupane
Copy link
Contributor

sobitneupane commented Dec 29, 2022

Copy the text with Ctrl+C from expensify and paste with with "Ctrl + Shift + V", new lines get added.

  1. Send the following text in new expensify.
I'm around if you are and wanna hop on a call https://meet.google.com/yjx-maas-pku



Nothing specific in mind
  1. Select the text and copy it with Ctrl+C.
  2. Paste the text with Ctrl + Shift +V
trimmed.mov

@tgolen
Copy link
Contributor Author

tgolen commented Dec 29, 2022

When I copy the text from Github and paste it with "Ctrl+Shift+V", newlines get removed.

I might be wrong here, but I think I remember seeing a discussion about this and since GitHub formats its code blocks differently, we weren't going to bother with trying to preserve them perfectly. I'm having trouble finding the conversation, but do you feel that issue is in scope of the original GH?

Copy the text with Ctrl+C from expensify and paste with with "Ctrl + Shift + V", new lines get added.

I am not able to reproduce this one. Any pointers on what I'm doing differently?

2022-12-29_11-49-30.mp4

@sobitneupane
Copy link
Contributor

So, I believe this issue is reproducible when the message contains link

Can you try sending something like

I'm around if you are and wanna hop on a call https://meet.google.com/yjx-maas-pku



Nothing specific in mind

@tgolen
Copy link
Contributor Author

tgolen commented Jan 2, 2023

OK, I'll test it out with a link, but that is sure weird why a link would matter. I wonder if that's messing up a regex somewhere...

@tgolen
Copy link
Contributor Author

tgolen commented Jan 2, 2023

All right, I tried it with the link, and I still can't reproduce it 🤔

This video shows me pasting twice. The first time is a normal paste with formatting, the second time is a paste without formatting. In both cases, the newlines are the same (you can see the link is treated a little differently though which is expected).

2023-01-02_09-22-31.mp4

@sobitneupane
Copy link
Contributor

@tgolen I can still reproduce the issue on my end.

Steps to reproduce:

  1. Send a message with links and newlines
  2. Copy the message
  3. Paste the message with Ctrl + Shift + V or Paste and Match Style on context menu.
Screen.Recording.2023-01-03.at.21.19.45.mov

@tgolen
Copy link
Contributor Author

tgolen commented Jan 3, 2023

OK, I see in that video you are copying the message by using the context menu. That is different then from when you previously reported it, right? Can you verify if there is a difference between using the context menu and using CTRL+C to copy the message?

@sobitneupane
Copy link
Contributor

Can you verify if there is a difference between using the context menu and using CTRL+C to copy the message?

There is no difference. Both context menu "Copy to clipboard" and CTRL+C has the same result.

Screen.Recording.2023-01-03.at.21.57.08.mov

@tgolen
Copy link
Contributor Author

tgolen commented Jan 3, 2023

OK, since I am not able to reproduce it, are there any changes to the code you would suggest? Any idea why you can reproduce it but I can't?

@tgolen
Copy link
Contributor Author

tgolen commented Jan 3, 2023

I just tested it again this morning and I can reproduce the problem 🤦 sorry about that! I'll keep digging

@tgolen
Copy link
Contributor Author

tgolen commented Jan 3, 2023

All right, I found a different place to double the newlines for the context menu which seems to work better and fix the issue. Can you please test again? Thanks for your persistence on this!

@sobitneupane
Copy link
Contributor

sobitneupane commented Jan 4, 2023

@tgolen It solves the above issue.

But with following steps, newlines are still getting added.

  1. Send a message containing link.
  2. Select the message.
  3. From context menu, click on "Copy to clipboard"
  4. Paste the message on Composer with CTRL + SHIFT + V or Select Paste and Match Style on context menu.
Screen.Recording.2023-01-04.at.13.18.34.mov

@tgolen
Copy link
Contributor Author

tgolen commented Jan 5, 2023

OK, that is unfortunate. I will need to think about how to fix that 🤔

@tgolen
Copy link
Contributor Author

tgolen commented Jan 6, 2023

All right, I pushed an update to fix what happens when you copy (or cut) stuff from inside the composer input

@tgolen
Copy link
Contributor Author

tgolen commented Jan 6, 2023

I also added that to the list of tests

@sobitneupane
Copy link
Contributor

sobitneupane commented Jan 6, 2023

Screenshots/Videos

Web
Screen.Recording.2023-01-06.at.20.14.09.mov
Mobile Web - Chrome
Screen.Recording.2023-01-06.at.21.01.46.mov
Mobile Web - Safari
Desktop
Screen.Recording.2023-01-06.at.20.21.28.mov
iOS
RPReplay_Final1673017424.MP4
Android
Screen.Recording.2023-01-06.at.20.38.07.mov

@sobitneupane
Copy link
Contributor

@tgolen This issue still exists on mWeb both on android - Chrome and IOS-safari.

Screen.Recording.2023-01-06.at.21.01.46.mov

@sobitneupane
Copy link
Contributor

@tgolen It looks like #13739 (comment) issue is not present in staging. But when copied from other sources(notes, docs) and pasted in app (and vice versa), there are inconsistencies in staging as well.

@tgolen
Copy link
Contributor Author

tgolen commented Jan 6, 2023

@sobitneupane Thanks! I am going to go out on a limb and say that the mobile web issue is OK for now. I don't think that platform provides a very good UX for copy/pasting text within the composer.

Copy link
Contributor

@sobitneupane sobitneupane left a comment

Choose a reason for hiding this comment

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

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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 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
    • 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 correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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(themeColors.componentBG)
  • 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

LGTM and tests well. Thanks for all the comments - it made reviewing the PR really easy and I'm sure it will help others who come across these lines too!

@luacmartins
Copy link
Contributor

all yours @robertjchen!

Copy link
Contributor

@robertjchen robertjchen left a comment

Choose a reason for hiding this comment

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

Code/Comments look great and it tests well on my end as well, this is good to go! 👍

@robertjchen robertjchen merged commit 6a43fc7 into main Jan 10, 2023
@robertjchen robertjchen deleted the tgolen-fix-paste-extra-lines branch January 10, 2023 15:45
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @robertjchen in version: 1.2.52-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @Julesssss in version: 1.2.52-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@mollfpr
Copy link
Contributor

mollfpr commented Feb 16, 2023

Hi!! Coming from this issue #14243 where the PR is introducing the regression specifically on this code const plainText = Str.htmlDecode(parser.htmlToText(content)).replace(/\n/g, '\n\n'); —the explanation at here #14243 (comment).

Thank you!

@sobitneupane
Copy link
Contributor

The PR introduces this regression.

Steps To Reproduce:

  • Highlight text with the cursor with few line breaks
  • Right click on the hightailed text --> click on the Copy icon at the Context menu
  • Paste result to the chat

The regression is now fixed by #16464

@eVoloshchak
Copy link
Contributor

The same issue is happening when you copy highlighted text using ctrl/cmd+c, this has been resolved in #16473

Comment on lines +292 to +294
if (!event.metaKey || (event.key !== 'c' && event.key !== 'x')) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@tgolen Here we are only checking for the metaKey modifier which is only available on macOS. I'm not sure if this is intended but I think we should also check for ctrlKey to have same behaviour on other OS (Windows & Linux).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds fine to me, but it's very low value since we don't officially support those platforms. Just my thoughts

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we are removing the whole putSelectionInClipboard function here #19738. We no longer need it as the issue that this function was meant to solve is already fixed by #15034 and the original issue #12769 is no longer reproducible.

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.

8 participants