Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ exports[`RichText should make bold after split and merge 1`] = `
<!-- /wp:paragraph -->"
`;

exports[`RichText should navigate arround emoji 1`] = `
"<!-- wp:paragraph -->
<p>1🍓</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should not format text after code backtick 1`] = `
"<!-- wp:paragraph -->
<p>A <code>backtick</code> and more.</p>
Expand Down
12 changes: 12 additions & 0 deletions packages/e2e-tests/specs/editor/various/rich-text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
} );
32 changes: 12 additions & 20 deletions packages/rich-text/src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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(
Expand Down