-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't send empty paragraph tags to view on Android #22561
Changes from all commits
ca2cf3b
c7cb54a
eace29c
90f8442
47494b5
4bd5342
242c6e0
f664971
c645872
76cb481
2eaf1ec
ddfea57
8f9bd43
b3c66fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ const gutenbergFormatNamesToAztec = { | |
'core/strikethrough': 'strikethrough', | ||
}; | ||
|
||
const EMPTY_PARAGRAPH_TAGS = '<p></p>'; | ||
|
||
export class RichText extends Component { | ||
constructor( { | ||
value, | ||
|
@@ -80,7 +82,8 @@ export class RichText extends Component { | |
|
||
this.isIOS = Platform.OS === 'ios'; | ||
this.createRecord = this.createRecord.bind( this ); | ||
this.onChange = this.onChange.bind( this ); | ||
this.restoreParagraphTags = this.restoreParagraphTags.bind( this ); | ||
this.onChangeFromAztec = this.onChangeFromAztec.bind( this ); | ||
this.onKeyDown = this.onKeyDown.bind( this ); | ||
this.handleEnter = this.handleEnter.bind( this ); | ||
this.handleDelete = this.handleDelete.bind( this ); | ||
|
@@ -264,7 +267,7 @@ export class RichText extends Component { | |
/* | ||
* Handles any case where the content of the AztecRN instance has changed | ||
*/ | ||
onChange( event ) { | ||
onChangeFromAztec( event ) { | ||
const contentWithoutRootTag = this.removeRootTagsProduceByAztec( | ||
unescapeSpaces( event.nativeEvent.text ) | ||
); | ||
|
@@ -283,14 +286,29 @@ export class RichText extends Component { | |
const contentWithoutRootTag = this.removeRootTagsProduceByAztec( | ||
unescapeSpaces( event.nativeEvent.text ) | ||
); | ||
let formattedContent = contentWithoutRootTag; | ||
if ( ! this.isIOS ) { | ||
formattedContent = this.restoreParagraphTags( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Text with removed paragraph tags from https://github.com/WordPress/gutenberg/pull/22561/files#r478829512 can not pass from RCTAztecView to the RichText |
||
contentWithoutRootTag, | ||
this.multilineTag | ||
); | ||
} | ||
|
||
this.debounceCreateUndoLevel(); | ||
const refresh = this.value !== contentWithoutRootTag; | ||
this.value = contentWithoutRootTag; | ||
const refresh = this.value !== formattedContent; | ||
this.value = formattedContent; | ||
|
||
// we don't want to refresh if our goal is just to create a record | ||
if ( refresh ) { | ||
this.props.onChange( contentWithoutRootTag ); | ||
this.props.onChange( formattedContent ); | ||
} | ||
} | ||
|
||
restoreParagraphTags( value, tag ) { | ||
if ( tag === 'p' && ( ! value || ! value.startsWith( '<p>' ) ) ) { | ||
return '<p>' + value + '</p>'; | ||
} | ||
return value; | ||
} | ||
|
||
/* | ||
|
@@ -708,8 +726,11 @@ export class RichText extends Component { | |
value = ''; | ||
} | ||
// On android if content is empty we need to send no content or else the placeholder will not show. | ||
if ( ! this.isIOS && value === '' ) { | ||
return value; | ||
if ( | ||
! this.isIOS && | ||
( value === '' || value === EMPTY_PARAGRAPH_TAGS ) | ||
) { | ||
return ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures that empty paragraph tags do not get passed to the RCTAztecView (thus hiding the placeholder) |
||
} | ||
|
||
if ( tagName ) { | ||
|
@@ -848,7 +869,7 @@ export class RichText extends Component { | |
defaultPlaceholderTextColor | ||
} | ||
deleteEnter={ this.props.deleteEnter } | ||
onChange={ this.onChange } | ||
onChange={ this.onChangeFromAztec } | ||
onFocus={ this.onFocus } | ||
onBlur={ this.onBlur } | ||
onKeyDown={ this.onKeyDown } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated method name to help distinguish from
this.props.onChange
which is used many times elsewhere in this class.