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
4 changes: 4 additions & 0 deletions packages/rich-text/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Raise the minimum required Node.js version to `>=22.13.0`, for stable `require(esm)` support ([#84313](https://github.com/WordPress/gutenberg/pull/84313)).
- Remove refs from `KeyboardShortcutContext` and `InputEventContext` context values and pass `Set`s directly. Also affects the `shortcutsListener` and `inputEventsListener` parameters and replaces the `EventListenersProps` type with `EventCallbacksSet` ([#84545](https://github.com/WordPress/gutenberg/pull/84545)).

### Bug Fixes

- `getTextContent`: Remove every object replacement character from the returned text, not just the first one ([#81526](https://github.com/WordPress/gutenberg/pull/81526)).

### Internal

- Refactor to TypeScript ([#84324](https://github.com/WordPress/gutenberg/pull/84324), [#84365](https://github.com/WordPress/gutenberg/pull/84365), [#84378](https://github.com/WordPress/gutenberg/pull/84378)).
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/get-text-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import type { RichTextValue } from './types';
* @return {string} The text content.
*/
export function getTextContent( { text }: Pick< RichTextValue, 'text' > ) {
return text.replace( OBJECT_REPLACEMENT_CHARACTER, '' );
return text.replaceAll( OBJECT_REPLACEMENT_CHARACTER, '' );
}
23 changes: 23 additions & 0 deletions packages/rich-text/src/test/get-text-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from 'vitest';
import { getTextContent } from '../get-text-content';
import { OBJECT_REPLACEMENT_CHARACTER } from '../special-characters';

describe( 'getTextContent', () => {
it( 'should return the text as is when it holds no objects', () => {
expect( getTextContent( { text: 'one two' } ) ).toBe( 'one two' );
} );

it( 'should remove a single object replacement character', () => {
expect(
getTextContent( { text: `a${ OBJECT_REPLACEMENT_CHARACTER }b` } )
).toBe( 'ab' );
} );

it( 'should remove every object replacement character', () => {
expect(
getTextContent( {
text: `a${ OBJECT_REPLACEMENT_CHARACTER }b${ OBJECT_REPLACEMENT_CHARACTER }c`,
} )
).toBe( 'abc' );
} );
} );
29 changes: 29 additions & 0 deletions test/e2e/specs/editor/blocks/heading.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,35 @@ test.describe( 'Heading', () => {
).toHaveText( 'My new name' );
} );

test( 'Should leave inline objects out of the list view label', async ( {
editor,
page,
} ) => {
const imageSrc =
'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
await editor.insertBlock( {
name: 'core/heading',
attributes: {
content: `One<img src="${ imageSrc }">Two<img src="${ imageSrc }">Three`,
},
} );

await page
.getByRole( 'toolbar', { name: 'Document tools' } )
.getByRole( 'button', { name: 'Document Overview' } )
.click();

// Each inline image is one object replacement character in the
// value, and none of them should reach the plain text label.
await expect(
page
.getByRole( 'treegrid', {
name: 'Block navigation structure',
} )
.getByRole( 'link' )
).toHaveText( 'OneTwoThree' );
} );

test.describe( 'Block transforms', () => {
test.describe( 'FROM paragraph', () => {
test( 'should preserve the content', async ( { editor } ) => {
Expand Down
Loading