-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Rich Text: Prevent line breaks when disableLineBreaks is true #67412
base: trunk
Are you sure you want to change the base?
Rich Text: Prevent line breaks when disableLineBreaks is true #67412
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @markhowellsmead. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Looks good to me. |
// When line breaks are disabled, convert all line breaks to a single space. | ||
plainText = disableLineBreaks | ||
? plainText.replace( /\r?\n/g, ' ' ).trim() | ||
: plainText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you paste HTML? This doesn't look like a complete solution. Could you modify valueToInsert
within pasteInline
instead? We should strip out all the \n
there. There's a rich text replace function I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ellatrix,
Thank you for the thoughtful review. I've implemented the solution by modifying valueToInsert
within pasteInline
using the rich-text replace
function as you recommended.
Could you please review the changes
Hello @Infinite-Null |
Thank you, this looks better. Could you add an e2e test? |
Sure @ellatrix, |
Hi @ellatrix, Screencast:Screen.Recording.2025-01-07.at.10.09.34.AM.mov |
Fixes: #67387
What?
Modify
RichText
paste handling to correctly handle line breaks whendisableLineBreaks
is set to trueWhy?
Currently, when pasting text into a RichText component with disableLineBreaks={true}, line breaks are being converted to
tags instead of being stripped out as expected. This breaks the intended functionality of preventing line breaks in the component.
Testing Instructions
Screencast
Before Patch
Screen.Recording.2024-11-29.at.2.17.22.PM.mov
After Patch
Screen.Recording.2024-11-29.at.2.12.49.PM.mov