Skip to content

Preserve style after double line break#5692

Closed
ivailop7 wants to merge 1 commit intofacebook:mainfrom
ivailop7:preserve_style
Closed

Preserve style after double line break#5692
ivailop7 wants to merge 1 commit intofacebook:mainfrom
ivailop7:preserve_style

Conversation

@ivailop7
Copy link
Copy Markdown
Collaborator

@ivailop7 ivailop7 commented Mar 9, 2024

Fixes: #5620

The issue: When you press Enter twice, the styling gets lost in the skipped paragraph, same when you type inside a table cells.
Why change this: consistent behaviour with other text editors.

This essentially undoes the changes done in here: #5292 while still fixing the issue that PR officially addressed.

Before:

2024-03-09_18-52-45.mp4

After:

2024-03-09_18-59-13.mp4

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 9, 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 Mar 10, 2024 11:29am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 10, 2024 11:29am

@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 Mar 9, 2024
@ivailop7 ivailop7 changed the title Preserve style after double link breaks Preserve style after double line break Mar 9, 2024
Copy link
Copy Markdown
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Hmm, which editors are you checking against for the table case? What I can see on GDocs and Word is that they retain the format regardless of whether you click again, but only for that specific position.

For the create paragraph, my hunch is that this logic is a one-off and they simply replicate the format when you insert a new paragraph.

Also, this PR seems to be preserving the style when clicking on a element position.

Screen.Recording.2024-03-12.at.9.42.24.AM.mov

@zurfyx
Copy link
Copy Markdown
Member

zurfyx commented Mar 12, 2024

^ We should really be writing some tests for all this discussion we're having above 😛

@ivailop7
Copy link
Copy Markdown
Collaborator Author

Hmm, which editors are you checking against for the table case? What I can see on GDocs and Word is that they retain the format regardless of whether you click again, but only for that specific position.

For the create paragraph, my hunch is that this logic is a one-off and they simply replicate the format when you insert a new paragraph.

Also, this PR seems to be preserving the style when clicking on a element position.

Screen.Recording.2024-03-12.at.9.42.24.AM.mov

Fair enough on tables, happy to keep it losing the current style between cells.

Losing the current format after a double line break, should be fixed though. If you have better suggestion on the approach, open to suggestions, since this is a super annoying problem when using the editor extensively.
I went with cleaning up the element node style nullifying because you can apply a style to a link node already and I couldn't find a use case when no style made sense, could be wrong. Happy to go for an alternative approach.

@zurfyx
Copy link
Copy Markdown
Member

zurfyx commented Mar 12, 2024

Hmm, which editors are you checking against for the table case? What I can see on GDocs and Word is that they retain the format regardless of whether you click again, but only for that specific position.
For the create paragraph, my hunch is that this logic is a one-off and they simply replicate the format when you insert a new paragraph.
Also, this PR seems to be preserving the style when clicking on a element position.
Screen.Recording.2024-03-12.at.9.42.24.AM.mov

Fair enough on tables, happy to keep it losing the current style between cells.

Losing the current format after a double line break, should be fixed though. If you have better suggestion on the approach, open to suggestions, since this is a super annoying problem when using the editor extensively. I went with cleaning up the element node style nullifying because you can apply a style to a link node already and I couldn't find a use case when no style made sense, could be wrong. Happy to go for an alternative approach.

Gave it a stab since I wasn't sure either, happy to follow up with a polished PR if you want - main...eventsftw

Screen.Recording.2024-03-12.at.2.37.16.PM.mov

This should be very close to Word and GDoc. They seem to reset format but they leverage the empty "TextNode" to store this information when there's no text (this is a guess, I have no idea about their codebase).

@ivailop7
Copy link
Copy Markdown
Collaborator Author

Hmm, which editors are you checking against for the table case? What I can see on GDocs and Word is that they retain the format regardless of whether you click again, but only for that specific position.
For the create paragraph, my hunch is that this logic is a one-off and they simply replicate the format when you insert a new paragraph.
Also, this PR seems to be preserving the style when clicking on a element position.
Screen.Recording.2024-03-12.at.9.42.24.AM.mov

Fair enough on tables, happy to keep it losing the current style between cells.
Losing the current format after a double line break, should be fixed though. If you have better suggestion on the approach, open to suggestions, since this is a super annoying problem when using the editor extensively. I went with cleaning up the element node style nullifying because you can apply a style to a link node already and I couldn't find a use case when no style made sense, could be wrong. Happy to go for an alternative approach.

Gave it a stab since I wasn't sure either, happy to follow up with a polished PR if you want - main...eventsftw

Screen.Recording.2024-03-12.at.2.37.16.PM.mov
This should be very close to Word and GDoc. They seem to reset format but they leverage the empty "TextNode" to store this information when there's no text (this is a guess, I have no idea about their codebase).

Looking good, you can use $getPreviousSelection I think, the rest makes sense. Go for a proper PR :)

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to keep formatting between lines?

3 participants