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

Fix issues with newlines when copypasting #15034

Merged

Conversation

TMisiukiewicz
Copy link
Contributor

Details

Unified the way of copy-pasting texts in the Composer. After that change, when pasting text into Composer input, the amount of newlines will remain unchanged, no matter what the source of the copied text is.

Fixed Issues

$ #14243
$ #14337
PROPOSAL: #14243 (comment)

Tests

As @tgolen did an amazing job with putting all the test scenarios together, i'll just copy-paste the list from #13739

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

Offline tests

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

QA Steps

Same as above

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
      • 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 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
WEB.mov
Mobile Web - Chrome
ANDROID-WEB.mov
Mobile Web - Safari
IOS-WEB.mov
Desktop
DESKTOP.mov
iOS
IOS.mov
Android
ANDROID.mov

@TMisiukiewicz TMisiukiewicz requested a review from a team as a code owner February 10, 2023 09:09
@melvin-bot melvin-bot bot requested review from Luke9389 and rushatgabhane and removed request for a team February 10, 2023 09:09
@MelvinBot
Copy link

@Luke9389 @rushatgabhane 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]

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2023

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

@TMisiukiewicz
Copy link
Contributor Author

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

@mollfpr
Copy link
Contributor

mollfpr commented Feb 10, 2023

@mountiny This PR request review from #14337 assignment 😅

For clarity, whos gonna be reviewing this one?

@mountiny
Copy link
Contributor

Asked in Slack

@mountiny mountiny requested review from mollfpr and removed request for rushatgabhane February 10, 2023 17:57
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Code looks good to me and testingn went well too:

Web:

pr15034web.mp4

mWeb iOS:
image

@mollfpr
Copy link
Contributor

mollfpr commented Feb 12, 2023

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.

Screenshots/Videos

Web
15034.Web.mov
Mobile Web - Chrome
15034.mWeb-Chrome.mp4
Mobile Web - Safari
15034.mWeb-Safari.mp4
Desktop
15034.Desktop.mov
iOS
15034.iOS.mp4
Android
15034.Android.mp4

Copy link
Contributor

@mollfpr mollfpr left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Thank you @mollfpr

@mountiny mountiny merged commit 39d9b66 into Expensify:main Feb 12, 2023
@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.

@github-actions
Copy link
Contributor

Performance Comparison Report 📊

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Duration
App start TTI 699.218 ms → 728.232 ms (+29.014 ms, +4.1%)
Open Search Page TTI 603.975 ms → 615.592 ms (+11.617 ms, +1.9%)
App start runJsBundle 191.844 ms → 199.323 ms (+7.479 ms, +3.9%)
App start nativeLaunch 19.406 ms → 21.000 ms (+1.594 ms, +8.2%)
App start regularAppStart 0.014 ms → 0.015 ms (+0.001 ms, +8.7%)
Show details
Name Duration
App start TTI Baseline
Mean: 699.218 ms
Stdev: 29.957 ms (4.3%)
Runs: 643.4436579998583 656.8447019997984 658.6793869994581 667.7808250002563 668.6047729998827 669.2858249992132 670.9166030008346 671.3821690008044 673.4516809992492 679.8080860003829 689.6787630002946 689.9955240003765 690.7557239998132 692.7901739999652 693.7384789995849 693.833552999422 694.2334090005606 695.11160299927 705.5836730003357 706.9385960008949 708.5699909999967 710.2372520007193 714.1422620005906 715.3143140003085 717.2596760001034 724.3892749994993 727.2208309993148 735.3631200008094 737.1767200008035 738.5099880006164 754.0215380005538 779.9120470006019

Current
Mean: 728.232 ms
Stdev: 26.400 ms (3.6%)
Runs: 678.6832079999149 688.6383590009063 690.5679960008711 693.5348969995975 702.7730090003461 704.0157789997756 704.2790200002491 707.7417849991471 708.511747000739 709.9352679997683 718.4148500002921 718.9889909997582 719.2381960004568 724.9890230000019 728.6559980008751 731.0650869999081 731.5457129999995 732.6203840002418 732.695395000279 735.8501960001886 736.4632559996098 739.2354269996285 739.7223039995879 745.9385010004044 748.5725749991834 748.7395539991558 748.95843099989 757.5144829992205 777.6876490004361 781.9835909996182 787.6268099993467
Open Search Page TTI Baseline
Mean: 603.975 ms
Stdev: 17.512 ms (2.9%)
Runs: 580.0677489992231 582.7127689998597 585.162679001689 586.0609540008008 586.3189289998263 589.8731690011919 590.3656009994447 590.6196300014853 590.6448569986969 591.8924160003662 593.6052250005305 594.0376389995217 595.7081710007042 597.4826260004193 598.1344809997827 601.156330998987 601.4289149995893 601.438110999763 602.5803219992667 602.7705080006272 602.8859869986773 606.6582850012928 608.5915120001882 611.9030769988894 612.4046229999512 613.1451830007136 618.4210209995508 627.7645670007914 635.6746829990298 636.8982339985669 644.7138270009309 646.0636400002986

Current
Mean: 615.592 ms
Stdev: 18.492 ms (3.0%)
Runs: 583.7187099996954 589.1809089984745 590.2508540004492 594.5893559996039 597.7122799996287 598.4618330001831 601.0482179988176 601.0925699993968 601.7411700002849 603.2119960002601 604.507325001061 605.1136079989374 606.8291020002216 607.1181639991701 607.2569989990443 610.1752519998699 610.8776450008154 612.2732750009745 614.0418699998409 614.3175859991461 620.4613039996475 623.8063559997827 626.8551030009985 628.997192999348 631.4728999994695 633.184529999271 633.3264569994062 634.3535980004817 635.4602860007435 642.6041669994593 643.1678869985044 644.1291099991649 663.1927490010858
App start runJsBundle Baseline
Mean: 191.844 ms
Stdev: 20.255 ms (10.6%)
Runs: 159 161 166 171 171 176 176 177 179 179 181 184 184 185 188 189 189 190 191 191 193 194 195 205 207 207 215 216 217 220 236 247

Current
Mean: 199.323 ms
Stdev: 14.506 ms (7.3%)
Runs: 175 177 178 179 184 186 189 190 191 192 194 195 195 196 196 196 196 197 202 203 204 205 209 211 211 213 216 218 219 225 237
App start nativeLaunch Baseline
Mean: 19.406 ms
Stdev: 1.578 ms (8.1%)
Runs: 17 17 18 18 18 18 18 18 18 18 18 19 19 19 19 19 19 19 19 19 20 20 20 21 21 21 21 21 21 22 23 23

Current
Mean: 21.000 ms
Stdev: 2.151 ms (10.2%)
Runs: 18 18 18 19 19 19 19 19 19 20 20 20 20 20 20 20 21 21 21 21 22 22 22 22 23 23 23 23 24 24 25 27
App start regularAppStart Baseline
Mean: 0.014 ms
Stdev: 0.001 ms (4.8%)
Runs: 0.012736000120639801 0.01297999918460846 0.013020999729633331 0.013101998716592789 0.013102000579237938 0.013142000883817673 0.01314299926161766 0.01314300112426281 0.01314300112426281 0.013387000188231468 0.013426998630166054 0.013426998630166054 0.01342799887061119 0.01342800073325634 0.01355000026524067 0.013590000569820404 0.013753000646829605 0.013753999024629593 0.014079000800848007 0.014119001105427742 0.014119001105427742 0.0142000000923872 0.014281999319791794 0.014281999319791794 0.01440500095486641 0.014445001259446144 0.014445001259446144 0.014607999473810196 0.01464799977838993 0.015177000313997269 0.01521800085902214

Current
Mean: 0.015 ms
Stdev: 0.001 ms (5.9%)
Runs: 0.013061000034213066 0.013508999720215797 0.013712000101804733 0.013915998861193657 0.013916000723838806 0.014078998938202858 0.014159999787807465 0.014241000637412071 0.014445001259446144 0.014607999473810196 0.01464799977838993 0.01464799977838993 0.014728998765349388 0.01476999931037426 0.01489199884235859 0.014932999387383461 0.014932999387383461 0.015014998614788055 0.015015000477433205 0.015095999464392662 0.01521800085902214 0.01550300046801567 0.015543999150395393 0.015544001013040543 0.015583999454975128 0.015705998986959457 0.015869000926613808 0.016235999763011932 0.01635799929499626 0.016439000144600868 0.016439000144600868 0.016478998586535454

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.2.71-0 🚀

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

Comment on lines -115 to -118
// Thanks to how browsers work, when text is highlighted and CTRL+c is pressed, browsers end up doubling the amount of newlines. Since the code in this file is
// triggered from a context menu and not CTRL+c, the newlines need to be doubled so that the content that goes into the clipboard is consistent with CTRL+c behavior.
// The extra newlines are stripped when the contents are pasted into the compose input, but if the contents are pasted outside of the comment composer, it will
// contain extra newlines and that's OK because it is consistent with CTRL+c behavior.
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we ever get to the bottom of why this comment was added or whether it's accurate? Maybe this wasn't browser behavior after all?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's very possible I was misunderstanding the behavior when I wrote that comment :D

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.2.71-1 🚀

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

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.

7 participants