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

Post title: fix single line paste #42321

Merged
merged 3 commits into from
Jul 15, 2022
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
10 changes: 8 additions & 2 deletions packages/editor/src/components/post-title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ function PostTitle( _, forwardedRef ) {
plainText,
} );

if ( typeof content !== 'string' && content.length ) {
event.preventDefault();
event.preventDefault();
ellatrix marked this conversation as resolved.
Show resolved Hide resolved

if ( ! content.length ) {
return;
}

if ( typeof content !== 'string' ) {
const [ firstBlock ] = content;

if (
Expand All @@ -164,6 +168,8 @@ function PostTitle( _, forwardedRef ) {
} else {
onInsertBlockAfter( content );
}
} else {
onUpdate( content );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
19 changes: 19 additions & 0 deletions test/e2e/specs/editor/various/copy-cut-paste.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,23 @@ test.describe( 'Copy/cut/paste', () => {
await pageUtils.pressKeyWithModifier( 'primary', 'v' );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );

test( 'should paste single line in post title', async ( {
page,
pageUtils,
} ) => {
// This test checks whether we are correctly handling single line
// pasting in the post title. Previously we were accidentally falling
// back to default browser behaviour, allowing the browser to insert
// unfiltered HTML. When we swap out the post title in the post editor
// with the proper block, this test can be removed.
await pageUtils.setClipboardData( {
html: '<span style="border: 1px solid black">Hello World</span>',
} );
await pageUtils.pressKeyWithModifier( 'primary', 'v' );
// Expect the span to be filtered out.
expect(
await page.evaluate( () => document.activeElement.innerHTML )
).toMatchSnapshot();
} );
} );