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 input rules #20964

Merged
merged 2 commits into from
Mar 18, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ exports[`Heading should create a paragraph block below when pressing enter at th
<p></p>
<!-- /wp:paragraph -->"
`;

exports[`Heading should not work with the list input rule 1`] = `
"<!-- wp:heading -->
<h2>1. H</h2>
<!-- /wp:heading -->"
`;

exports[`Heading should work with the format input rules 1`] = `
"<!-- wp:heading -->
<h2><code>code</code></h2>
<!-- /wp:heading -->"
`;
14 changes: 14 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/heading.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ describe( 'Heading', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should not work with the list input rule', async () => {
await clickBlockAppender();
await page.keyboard.type( '## 1. H' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should work with the format input rules', async () => {
await clickBlockAppender();
await page.keyboard.type( '## `code`' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should create a paragraph block above when pressing enter at the start', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '## a' );
Expand Down
6 changes: 1 addition & 5 deletions packages/rich-text/src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,12 @@ class RichText extends Component {
clearTimeout( this.onInput.timeout );
this.onInput.timeout = setTimeout( this.onCreateUndoLevel, 1000 );

if ( ! allowPrefixTransformations ) {
return;
}

// Only run input rules when inserting text.
if ( inputType !== 'insertText' ) {
return;
}

if ( inputRule ) {
if ( allowPrefixTransformations && inputRule ) {
inputRule( change, this.valueToFormat );
}

Expand Down