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

Block library: When pressing enter on empty line new Paragraph blocks is crated #16880

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { omit } from 'lodash';
import { castArray, omit } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -64,9 +64,10 @@ class RichTextWrapper extends Component {
} );

if ( transformation ) {
onReplace( [
onReplace( castArray(
transformation.transform( { content: value.text } ),
] );
) );
return;
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/verse/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
AlignmentToolbar,
} from '@wordpress/block-editor';

export default function VerseEdit( { attributes, setAttributes, className, mergeBlocks } ) {
export default function VerseEdit( { attributes, setAttributes, className, mergeBlocks, onReplace } ) {
const { textAlign, content } = attributes;

return (
Expand All @@ -40,6 +40,7 @@ export default function VerseEdit( { attributes, setAttributes, className, merge
[ `has-text-align-${ textAlign }` ]: textAlign,
} ) }
onMerge={ mergeBlocks }
onReplace={ onReplace }
/>
</>
);
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/verse/tranforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import { createBlock } from '@wordpress/blocks';

const transforms = {
from: [
{
type: 'enter',
regExp: /\n$/,
transform: ( { content } ) => [
createBlock( 'core/verse', {
content: content.replace( /\n$/, '' ),
Copy link
Member Author

Choose a reason for hiding this comment

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

I guess, it's buggy but it's enough to get feedback :)

} ),
createBlock( 'core/paragraph' ),
],
},
{
type: 'block',
blocks: [ 'core/paragraph' ],
Expand Down