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 paste after focus #16857

Merged
merged 2 commits into from Aug 2, 2019

Conversation

@ellatrix
Copy link
Member

commented Aug 1, 2019

Description

Fixes #15724.

This is a small fix for the bug that duplicates the rich text contents after pasting in a rich text instance that just received focus.

How has this been tested?

Copy a small amount of text.
Open the Gutenberg demo content.
Place the caret at the end of the first paragraph.
Move selection out of the window: e.g. place the caret in the address bar.
Place the caret again at the end of the first paragraph.
Now paste the text.
No content should be duplicated.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
@gziolo
gziolo approved these changes Aug 2, 2019
Copy link
Member

left a comment

I tested the exact same action as posted in the issue and I could reproduce it on master but not in this branch. Great change 💯

I tested pasting at the beginning, in the middle and at the end of the Paragraph block. Tried also with Heading and List blocks.

@ellatrix

This comment has been minimized.

Copy link
Member Author

commented Aug 2, 2019

I’ll attempt to create an e2e test in just a bit. Thanks for the review!

@gziolo gziolo merged commit 2beadcd into master Aug 2, 2019

1 of 4 checks passed

Filter opened Filter opened
Details
Filter opened Filter opened
Details
Milestone It Milestone It
Details
Travis CI - Pull Request Build Passed
Details

@gziolo gziolo deleted the fix/paste-after-focus branch Aug 2, 2019

@gziolo

This comment has been minimized.

Copy link
Member

commented Aug 2, 2019

I’ll attempt to create an e2e test in just a bit. Thanks for the review!

Sounds great, I merged this change as I want to play again with Puppeteer upgrade and this might (or not) help with some of the intermittent issues :)

@gziolo gziolo added this to the Gutenberg 6.3 milestone Aug 2, 2019

@ellatrix

This comment has been minimized.

Copy link
Member Author

commented Aug 2, 2019

It doesn't seem possible to me to create an e2e test for this fix.

	it.only( 'should update internal selection after fresh focus', async () => {
		await page.keyboard.press( 'Enter' );
		await page.keyboard.type( '1' );
		// Focus the address bar (move focus out of the window).
		await pressKeyWithModifier( 'primary', 'l' );
		// Focus the rich text instance again (not at the start).
		await page.click( '.wp-block-paragraph', { button: 'middle' } );
		// Should internally set bold at selection.
		await pressKeyWithModifier( 'primary', 'b' );
		// "2" should be bold.
		await page.keyboard.type( '2' );

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

Doing this this manually fails, but in Puppeteer it succeeds. :)
Perhaps in some cases the selectionchange event is triggered, I'm not sure.

@ellatrix

This comment has been minimized.

Copy link
Member Author

commented Aug 2, 2019

Blurring the element seems to trigger it to fail. And it succeeds with this branch. Yay!

@ellatrix

This comment has been minimized.

Copy link
Member Author

commented Aug 2, 2019

@gziolo I doubt it will fix the intermittent failures. Puppeteer won't wait for an animation frame. Let me think about that. :D

@ellatrix ellatrix referenced this pull request Aug 2, 2019
5 of 5 tasks complete
ellatrix added a commit that referenced this pull request Aug 6, 2019
gziolo added a commit that referenced this pull request Aug 7, 2019
Upgrade Puppeteer (#16875)
* Update demo test to make it work with Vimeo mock

* Add e2e test

* Update selection on mouseup/keyup/touchend

* Try to fix e2e tests

* Attempt to upgrade Puppeteer

* Fix package-lock.json file

* Fix preview e2e

* Update snapshot

* Stabilise block hierarchy tests

* Remove new e2e test

* Simplify loop

* Remove puppeteer from devDependencies

* Remove cancelAnimationFrame

* Add e2e test for #16857

* Restore animation frame fix
gziolo added a commit that referenced this pull request Aug 29, 2019
Fix paste after focus (#16857)
* Fix paste after focus

* Fixed type in comment
gziolo added a commit that referenced this pull request Aug 29, 2019
Upgrade Puppeteer (#16875)
* Update demo test to make it work with Vimeo mock

* Add e2e test

* Update selection on mouseup/keyup/touchend

* Try to fix e2e tests

* Attempt to upgrade Puppeteer

* Fix package-lock.json file

* Fix preview e2e

* Update snapshot

* Stabilise block hierarchy tests

* Remove new e2e test

* Simplify loop

* Remove puppeteer from devDependencies

* Remove cancelAnimationFrame

* Add e2e test for #16857

* Restore animation frame fix
gziolo added a commit that referenced this pull request Aug 29, 2019
Fix paste after focus (#16857)
* Fix paste after focus

* Fixed type in comment
gziolo added a commit that referenced this pull request Aug 29, 2019
Upgrade Puppeteer (#16875)
* Update demo test to make it work with Vimeo mock

* Add e2e test

* Update selection on mouseup/keyup/touchend

* Try to fix e2e tests

* Attempt to upgrade Puppeteer

* Fix package-lock.json file

* Fix preview e2e

* Update snapshot

* Stabilise block hierarchy tests

* Remove new e2e test

* Simplify loop

* Remove puppeteer from devDependencies

* Remove cancelAnimationFrame

* Add e2e test for #16857

* Restore animation frame fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.