Skip to content

Commit c60c26c

Browse files
authored
Remove rootTagsToEliminate prop from native Rich Text component (#48983)
* Remove rootTagsToEliminate prop from Rich Text * Fix typo in removeRootTagsProducedByAztec function name
1 parent d0fa047 commit c60c26c

File tree

5 files changed

+8
-17
lines changed

5 files changed

+8
-17
lines changed

packages/block-editor/src/components/caption/index.native.js

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const Caption = ( {
4444
onChange={ onChange }
4545
placeholder={ placeholder }
4646
placeholderTextColor={ placeholderTextColor }
47-
rootTagsToEliminate={ [ 'p' ] }
4847
style={ style }
4948
tagName="p"
5049
textAlign="center"

packages/block-editor/src/components/rich-text/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ function removeNativeProps( props ) {
6666
textAlign,
6767
selectionColor,
6868
tagsToEliminate,
69-
rootTagsToEliminate,
7069
disableEditingMenu,
7170
fontSize,
7271
fontFamily,

packages/block-editor/src/components/rich-text/index.native.js

-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ function RichTextWrapper(
9797
textAlign,
9898
selectionColor,
9999
tagsToEliminate,
100-
rootTagsToEliminate,
101100
disableEditingMenu,
102101
fontSize,
103102
fontFamily,
@@ -628,7 +627,6 @@ function RichTextWrapper(
628627
textAlign={ textAlign }
629628
selectionColor={ selectionColor }
630629
tagsToEliminate={ tagsToEliminate }
631-
rootTagsToEliminate={ rootTagsToEliminate }
632630
disableEditingMenu={ disableEditingMenu }
633631
fontSize={ fontSize }
634632
fontFamily={ fontFamily }

packages/block-library/src/file/edit.native.js

-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ export class FileEdit extends Component {
466466
__unstableMobileNoFocusOnMount
467467
onChange={ this.onChangeFileName }
468468
placeholder={ __( 'File name' ) }
469-
rootTagsToEliminate={ [ 'p' ] }
470469
tagName="p"
471470
underlineColorAndroid="transparent"
472471
value={ fileName }
@@ -502,7 +501,6 @@ export class FileEdit extends Component {
502501
<RichText
503502
withoutInteractiveFormatting
504503
__unstableMobileNoFocusOnMount
505-
rootTagsToEliminate={ [ 'p' ] }
506504
tagName="p"
507505
textAlign="center"
508506
minWidth={ minWidth }

packages/rich-text/src/component/index.native.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class RichText extends Component {
205205

206206
valueToFormat( value ) {
207207
// Remove the outer root tags.
208-
return this.removeRootTagsProduceByAztec(
208+
return this.removeRootTagsProducedByAztec(
209209
toHTMLString( {
210210
value,
211211
multilineTag: this.multilineTag,
@@ -272,30 +272,27 @@ export class RichText extends Component {
272272
* Cleans up any root tags produced by aztec.
273273
* TODO: This should be removed on a later version when aztec doesn't return the top tag of the text being edited
274274
*/
275-
removeRootTagsProduceByAztec( html ) {
275+
removeRootTagsProducedByAztec( html ) {
276276
let result = this.removeRootTag( this.props.tagName, html );
277-
// Temporary workaround for https://github.com/WordPress/gutenberg/pull/13763
278-
if ( this.props.rootTagsToEliminate ) {
279-
this.props.rootTagsToEliminate.forEach( ( element ) => {
280-
result = this.removeRootTag( element, result );
281-
} );
282-
}
283277

284278
if ( this.props.tagsToEliminate ) {
285279
this.props.tagsToEliminate.forEach( ( element ) => {
286280
result = this.removeTag( element, result );
287281
} );
288282
}
283+
289284
return result;
290285
}
291286

292287
removeRootTag( tag, html ) {
293288
const openingTagRegexp = RegExp( '^<' + tag + '[^>]*>', 'gim' );
294289
const closingTagRegexp = RegExp( '</' + tag + '>$', 'gim' );
290+
295291
return html
296292
.replace( openingTagRegexp, '' )
297293
.replace( closingTagRegexp, '' );
298294
}
295+
299296
removeTag( tag, html ) {
300297
const openingTagRegexp = RegExp( '<' + tag + '>', 'gim' );
301298
const closingTagRegexp = RegExp( '</' + tag + '>', 'gim' );
@@ -312,7 +309,7 @@ export class RichText extends Component {
312309
return;
313310
}
314311

315-
const contentWithoutRootTag = this.removeRootTagsProduceByAztec(
312+
const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
316313
unescapeSpaces( event.nativeEvent.text )
317314
);
318315
// On iOS, onChange can be triggered after selection changes, even though there are no content changes.
@@ -327,7 +324,7 @@ export class RichText extends Component {
327324
}
328325

329326
onTextUpdate( event ) {
330-
const contentWithoutRootTag = this.removeRootTagsProduceByAztec(
327+
const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
331328
unescapeSpaces( event.nativeEvent.text )
332329
);
333330
let formattedContent = contentWithoutRootTag;
@@ -652,7 +649,7 @@ export class RichText extends Component {
652649
const realEnd = Math.max( start, end );
653650

654651
// Check and dicsard stray event, where the text and selection is equal to the ones already cached.
655-
const contentWithoutRootTag = this.removeRootTagsProduceByAztec(
652+
const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
656653
unescapeSpaces( event.nativeEvent.text )
657654
);
658655
if (

0 commit comments

Comments
 (0)