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

RichText: restore focus after setting selection #17617

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
Revert "Fix rich text e2e tests"
This reverts commit 1ab4854.
  • Loading branch information
ellatrix committed Sep 27, 2019

Verified

This commit was signed with the committer’s verified signature. The key has expired.
spastorino Santiago Pastorino
commit 92ed8062e31094859f164d59e52ae6a04ed15aeb
4 changes: 0 additions & 4 deletions packages/e2e-tests/specs/rich-text.test.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import {
insertBlock,
clickBlockAppender,
pressKeyWithModifier,
pressKeyTimes,
} from '@wordpress/e2e-test-utils';

describe( 'RichText', () => {
@@ -84,12 +83,10 @@ describe( 'RichText', () => {
await page.mouse.move( 0, 0 );
await page.mouse.move( 10, 10 );
await page.click( '[aria-label="Bold"]' );
await pressKeyTimes( 'Tab', 5 );
await page.keyboard.type( 'bold' );
await page.mouse.move( 0, 0 );
await page.mouse.move( 10, 10 );
await page.click( '[aria-label="Bold"]' );
await pressKeyTimes( 'Tab', 5 );
await page.keyboard.type( '.' );

expect( await getEditedPostContent() ).toMatchSnapshot();
@@ -241,7 +238,6 @@ describe( 'RichText', () => {

it( 'should handle Home and End keys', async () => {
await page.keyboard.press( 'Enter' );
await page.evaluate( () => new Promise( window.requestAnimationFrame ) );

await pressKeyWithModifier( 'primary', 'b' );
await page.keyboard.type( '12' );
14 changes: 14 additions & 0 deletions packages/rich-text/src/component/index.js
Original file line number Diff line number Diff line change
@@ -282,6 +282,20 @@ class RichText extends Component {

this.recalculateBoundaryStyle();

// We know for certain that on focus, the old selection is invalid. It
// will be recalculated on the next mouseup, keyup, or touchend event.
const index = undefined;
const activeFormats = undefined;

this.record = {
...this.record,
start: index,
end: index,
activeFormats,
};
this.props.onSelectionChange( index, index );
this.setState( { activeFormats } );

// Update selection as soon as possible, which is at the next animation
// frame. The event listener for selection changes may be added too late
// at this point, but this focus event is still too early to calculate