Skip to content
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

[Mobile] native mobile release v1.5.1 #15734

Merged
merged 4 commits into from May 20, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 26 additions & 13 deletions packages/block-editor/src/components/rich-text/index.native.js
Expand Up @@ -737,16 +737,22 @@ export class RichText extends Component {
let selection = null;
if ( this.needsSelectionUpdate ) {
this.needsSelectionUpdate = false;

// Aztec performs some html text cleanup while parsing it so, its internal representation gets out-of-sync with the
// representation of the format-lib on the RN side. We need to avoid trying to set the caret position because it may
// be outside the text bounds and crash Aztec, at least on Android.
if ( ! this.isIOS && this.willTrimSpaces( html ) ) {
// the html will get trimmed by the cleaning up functions in Aztec and caret position will get out-of-sync.
// So, skip forcing it, let Aztec just do its best and just log the fact.
console.warn( 'RichText value will be trimmed for spaces! Avoiding setting the caret position manually.' );
} else {
selection = { start: this.props.selectionStart, end: this.props.selectionEnd };
selection = { start: this.props.selectionStart, end: this.props.selectionEnd };

// On AztecAndroid, setting the caret to an out-of-bounds position will crash the editor so, let's check for some cases.
if ( ! this.isIOS ) {
// Aztec performs some html text cleanup while parsing it so, its internal representation gets out-of-sync with the
// representation of the format-lib on the RN side. We need to avoid trying to set the caret position because it may
// be outside the text bounds and crash Aztec, at least on Android.
if ( this.willTrimSpaces( html ) ) {
// the html will get trimmed by the cleaning up functions in Aztec and caret position will get out-of-sync.
// So, skip forcing it, let Aztec just do its best and just log the fact.
console.warn( 'RichText value will be trimmed for spaces! Avoiding setting the caret position manually.' );
selection = null;
} else if ( this.props.selectionStart > record.text.length || this.props.selectionEnd > record.text.length) {
console.warn( 'Oops, selection will land outside the text, skipping setting it...');
selection = null;
}
}
}

Expand Down Expand Up @@ -821,11 +827,18 @@ RichText.defaultProps = {

const RichTextContainer = compose( [
withInstanceId,
withBlockEditContext( ( { clientId, onFocus, isSelected, onCaretVerticalPositionChange }, ownProps ) => {
withBlockEditContext( ( { clientId, onFocus, onCaretVerticalPositionChange, isSelected }, ownProps ) => {
// ownProps.onFocus and isSelected needs precedence over the block edit context
if ( ownProps.isSelected !== undefined ) {
isSelected = ownProps.isSelected;
}
if ( ownProps.onFocus !== undefined ) {
onFocus = ownProps.onFocus;
}
return {
clientId,
isSelected,
onFocus: onFocus || ownProps.onFocus,
clientId,
onFocus,
onCaretVerticalPositionChange,
};
} ),
Expand Down