Skip to content

Commit

Permalink
Paste Handler: Try to fix pasting text with formatting (#63779)
Browse files Browse the repository at this point in the history
* Paste Handler: Try to fix pasting text with formatting

* Refactor e2e test

* Simplify e2e test

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: hellofromtonya <[email protected]>
Co-authored-by: ndiego <[email protected]>
Co-authored-by: rfischmann <[email protected]>
Co-authored-by: bph <[email protected]>
  • Loading branch information
7 people authored Sep 26, 2024
1 parent e0c5a59 commit 4482cd3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default ( props ) => ( element ) => {
} = props.current;

// The event listener is attached to the window, so we need to check if
// the target is the element.
if ( event.target !== element ) {
// the target is the element or inside the element.
if ( ! element.contains( event.target ) ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:paragraph -->
<p><strong>t<a href="https://wordpress.org/gutenberg">es</a>t</strong></p>
<!-- /wp:paragraph -->
21 changes: 21 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 @@ -565,6 +565,27 @@ test.describe( 'Copy/cut/paste', () => {
] );
} );

test( 'should paste link to formatted text', async ( {
page,
pageUtils,
editor,
} ) => {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: '<strong>test</strong>' },
} );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'ArrowRight' );
await pageUtils.pressKeys( 'shift+ArrowRight' );
await pageUtils.pressKeys( 'shift+ArrowRight' );
pageUtils.setClipboardData( {
plainText: 'https://wordpress.org/gutenberg',
html: 'https://wordpress.org/gutenberg',
} );
await pageUtils.pressKeys( 'primary+v' );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );

test( 'should auto-link', async ( { pageUtils, editor } ) => {
await editor.insertBlock( {
name: 'core/paragraph',
Expand Down

0 comments on commit 4482cd3

Please sign in to comment.