-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RichText: fix RTL keyboard interactions (#15496)
- Loading branch information
1 parent
c340184
commit b0e812e
Showing
7 changed files
with
225 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`RTL should arrow navigate 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>٠١٢</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
|
||
exports[`RTL should arrow navigate between blocks 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>٠<br>١</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:paragraph --> | ||
<p>٠<br>١<br>٢</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should merge backward 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>٠١</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should merge forward 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>٠١</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should navigate inline boundaries 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p><strong>١</strong>٠٢</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should navigate inline boundaries 2`] = ` | ||
"<!-- wp:paragraph --> | ||
<p><strong>١٠</strong>٢</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should navigate inline boundaries 3`] = ` | ||
"<!-- wp:paragraph --> | ||
<p><strong>٠١</strong>٢</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should navigate inline boundaries 4`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>٠<strong>١</strong>٢</p> | ||
<!-- /wp:paragraph -->" | ||
`; | ||
exports[`RTL should split 1`] = ` | ||
"<!-- wp:paragraph --> | ||
<p>٠</p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:paragraph --> | ||
<p>١</p> | ||
<!-- /wp:paragraph -->" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
createNewPost, | ||
getEditedPostContent, | ||
pressKeyWithModifier, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
// Avoid using three, as it looks too much like two with some fonts. | ||
const ARABIC_ZERO = '٠'; | ||
const ARABIC_ONE = '١'; | ||
const ARABIC_TWO = '٢'; | ||
|
||
describe( 'RTL', () => { | ||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
|
||
it( 'should arrow navigate', async () => { | ||
await page.evaluate( () => document.dir = 'rtl' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
// We need at least three characters as arrow navigation *from* the | ||
// edges might be handled differently. | ||
await page.keyboard.type( ARABIC_ONE ); | ||
await page.keyboard.type( ARABIC_TWO ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
// This is the important key press: arrow nav *from* the middle. | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.type( ARABIC_ZERO ); | ||
|
||
// Expect: ARABIC_ZERO + ARABIC_ONE + ARABIC_TWO (<p>٠١٢</p>). | ||
// N.b.: HTML is LTR, so direction will be reversed! | ||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should split', async () => { | ||
await page.evaluate( () => document.dir = 'rtl' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
await page.keyboard.type( ARABIC_ZERO ); | ||
await page.keyboard.type( ARABIC_ONE ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should merge backward', async () => { | ||
await page.evaluate( () => document.dir = 'rtl' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
await page.keyboard.type( ARABIC_ZERO ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( ARABIC_ONE ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'Backspace' ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should merge forward', async () => { | ||
await page.evaluate( () => document.dir = 'rtl' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
await page.keyboard.type( ARABIC_ZERO ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( ARABIC_ONE ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'Delete' ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should arrow navigate between blocks', async () => { | ||
await page.evaluate( () => document.dir = 'rtl' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
await page.keyboard.type( ARABIC_ZERO ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( ARABIC_ONE ); | ||
await pressKeyWithModifier( 'shift', 'Enter' ); | ||
await page.keyboard.type( ARABIC_TWO ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
|
||
// Move to the previous block with two lines in the current block. | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await pressKeyWithModifier( 'shift', 'Enter' ); | ||
await page.keyboard.type( ARABIC_ONE ); | ||
|
||
// Move to the next block with two lines in the current block. | ||
await page.keyboard.press( 'ArrowLeft' ); | ||
await page.keyboard.type( ARABIC_ZERO ); | ||
await pressKeyWithModifier( 'shift', 'Enter' ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'should navigate inline boundaries', async () => { | ||
await page.evaluate( () => document.dir = 'rtl' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
await pressKeyWithModifier( 'primary', 'b' ); | ||
await page.keyboard.type( ARABIC_ONE ); | ||
await pressKeyWithModifier( 'primary', 'b' ); | ||
await page.keyboard.type( ARABIC_TWO ); | ||
|
||
// Insert a character at each boundary position. | ||
for ( let i = 4; i > 0; i-- ) { | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await page.keyboard.type( ARABIC_ZERO ); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
|
||
await page.keyboard.press( 'Backspace' ); | ||
} | ||
} ); | ||
} ); |