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

[lexical][lexical-playground] Bug Fix: Create line break on paste of content type text/html #6376

Merged
merged 3 commits into from
Jul 9, 2024

Conversation

jnnwnk
Copy link
Contributor

@jnnwnk jnnwnk commented Jul 7, 2024

Description

Current behaviour

On copy past of text with content type text/html (e.g. from google docs), line breaks inside of paragraphs are ignored. The HTML looks like this (I removed styling attributes for better overview):

<html>
<body>
    <!--StartFragment-->
    <meta charset="utf-8">
    <b>
    	<br />
        <p dir="ltr">Test1</span><span><br /></span><span>Test2</span></p>
        <p dir="ltr">Test3</span></p>
    </b><br class="Apple-interchange-newline">
    <!--EndFragment-->
</body>
</html>

The first line break (before p tag) is recognized correctly.
The second line break (which is embedded between Test1 and Test2 in the first paragraph) gets lost.

Expected / Fixed behaviour

The line break is inserted correctly, no matter where it was placed.

Closes #5592

Test plan

Before

lexical-line-break-before-fix_XsA1rhKO.mp4

After

lexical-line-break-after-fix_gAjhcqd8.mp4

Copy link

vercel bot commented Jul 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2024 2:25pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2024 2:25pm

@facebook-github-bot
Copy link
Contributor

Hi @jnnwnk!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link

github-actions bot commented Jul 7, 2024

size-limit report 📦

Path Size
lexical - cjs 28.47 KB (0%)
lexical - esm 28.28 KB (0%)
@lexical/rich-text - cjs 36.86 KB (0%)
@lexical/rich-text - esm 28.08 KB (0%)
@lexical/plain-text - cjs 35.49 KB (0%)
@lexical/plain-text - esm 25.3 KB (0%)
@lexical/react - cjs 38.82 KB (0%)
@lexical/react - esm 29.27 KB (0%)

@jnnwnk jnnwnk changed the title [lexical] Bug Fix: Create line break on paste of content type text/html [lexical][lexical-playground] Bug Fix: Create line break on paste of content type text/html Jul 7, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 7, 2024
@jnnwnk jnnwnk marked this pull request as ready for review July 7, 2024 13:29
@jnnwnk
Copy link
Contributor Author

jnnwnk commented Jul 7, 2024

Hi guys, this is my first contribution to an open source project of this size.
Please let me know if I need to add anything further or what needs to be done so that the change can be merged.

@potatowagon
Copy link
Contributor

potatowagon commented Jul 9, 2024

tested with these cases

<ol>
  <li>
    1<br />3
  </li>
</ol>
 1<br />3
<pre>1<br />3</pre>

they are working

const parentElement = node.parentElement;
if (parentElement !== null) {
if (parentElement !== null && parentElement.tagName === 'P') {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could generalise this further to not convert all only child line breaks in block nodes, cause eg.

1
<div>
<br />
</div>
3

becomes

1


3

when it should be

1

3

doing on all block nodes would need more testing, ill look into it in a seperate PR.

meanwhile this change is an upgrade for lexical so i would be happy to merge once all the tests pass :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@potatowagon Are there any tests I need to fix/add?

The checks look good for me, except for After Approval which was skipped for any reason? If there is anything I can do to make this mergable, let me know :)

Copy link
Contributor

Choose a reason for hiding this comment

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

nothing needed, thanks for the fix!

@potatowagon potatowagon added the extended-tests Run extended e2e tests on a PR label Jul 9, 2024
@potatowagon potatowagon added this pull request to the merge queue Jul 9, 2024
Merged via the queue into facebook:main with commit 3ac2e91 Jul 9, 2024
77 checks passed
2wheeh pushed a commit to 2wheeh/lexical that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Pasting plain text into RichTextPlugin does not preserve line breaks
3 participants