diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/rich-text.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/rich-text.test.js.snap
index 9bd908b82d03fb..873b1e305b39b3 100644
--- a/packages/e2e-tests/specs/editor/various/__snapshots__/rich-text.test.js.snap
+++ b/packages/e2e-tests/specs/editor/various/__snapshots__/rich-text.test.js.snap
@@ -48,6 +48,12 @@ exports[`RichText should make bold after split and merge 1`] = `
"
`;
+exports[`RichText should navigate arround emoji 1`] = `
+"
+
1🍓
+"
+`;
+
exports[`RichText should not format text after code backtick 1`] = `
"
A backtick and more.
diff --git a/packages/e2e-tests/specs/editor/various/rich-text.test.js b/packages/e2e-tests/specs/editor/various/rich-text.test.js
index 2dd9f12ccd6cbd..282d42a8238dfe 100644
--- a/packages/e2e-tests/specs/editor/various/rich-text.test.js
+++ b/packages/e2e-tests/specs/editor/various/rich-text.test.js
@@ -415,4 +415,16 @@ describe( 'RichText', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
+
+ it( 'should navigate arround emoji', async () => {
+ await clickBlockAppender();
+ await page.keyboard.type( '🍓' );
+ // Only one press on arrow left should be required to move in front of
+ // the emoji.
+ await page.keyboard.press( 'ArrowLeft' );
+ await page.keyboard.type( '1' );
+
+ // Expect '1🍓'.
+ expect( await getEditedPostContent() ).toMatchSnapshot();
+ } );
} );
diff --git a/packages/rich-text/src/component/index.js b/packages/rich-text/src/component/index.js
index 6a14db55369d25..9e00a84fa97711 100644
--- a/packages/rich-text/src/component/index.js
+++ b/packages/rich-text/src/component/index.js
@@ -605,9 +605,6 @@ function RichText(
return;
}
- // In all other cases, prevent default behaviour.
- event.preventDefault();
-
const formatsBefore = formats[ start - 1 ] || EMPTY_ACTIVE_FORMATS;
const formatsAfter = formats[ start ] || EMPTY_ACTIVE_FORMATS;
@@ -650,30 +647,22 @@ function RichText(
}
}
- if ( newActiveFormatsLength !== currentActiveFormats.length ) {
- const newActiveFormats = source.slice( 0, newActiveFormatsLength );
- const newValue = {
- ...record.current,
- activeFormats: newActiveFormats,
- };
- record.current = newValue;
- applyRecord( newValue );
- setActiveFormats( newActiveFormats );
+ if ( newActiveFormatsLength === currentActiveFormats.length ) {
+ record.current._newActiveFormats = isReverse
+ ? formatsBefore
+ : formatsAfter;
return;
}
- const newPos = start + ( isReverse ? -1 : 1 );
- const newActiveFormats = isReverse ? formatsBefore : formatsAfter;
+ event.preventDefault();
+
+ const newActiveFormats = source.slice( 0, newActiveFormatsLength );
const newValue = {
...record.current,
- start: newPos,
- end: newPos,
activeFormats: newActiveFormats,
};
-
record.current = newValue;
applyRecord( newValue );
- onSelectionChange( newPos, newPos );
setActiveFormats( newActiveFormats );
}
@@ -860,8 +849,11 @@ function RichText(
...oldRecord,
start,
end,
- // Allow `getActiveFormats` to get new `activeFormats`.
- activeFormats: undefined,
+ // _newActiveFormats may be set on arrow key navigation to control
+ // the right boundary position. If undefined, getActiveFormats will
+ // give the active formats according to the browser.
+ activeFormats: oldRecord._newActiveFormats,
+ _newActiveFormats: undefined,
};
const newActiveFormats = getActiveFormats(