From d2a164beba3d5430dbac9d9b92b5385137720a21 Mon Sep 17 00:00:00 2001 From: Stefanos Togoulidis Date: Mon, 20 May 2019 15:50:41 +0300 Subject: [PATCH] [Mobile] native mobile release v1.5.1 (#15734) * Fix rich image caption toolbar and focus (#15685) * RichText: ownProps has precedence over block context. In this way, instances of RichText outside blocks can pass and handle their own custom onFocus and isSelected * RichText: Remove isSelected from block edit context. * Fix lint issues * RichText: Revert removing isSelected from block context (#15698) Removing it generates a regression where inserting a new list block, the block is not selected * Don't have AztecAndroid set caret if out-of-bounds * Fix lint issues --- .../src/components/rich-text/index.native.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index 6d2275d8e783e7..c9cb56397dcae2 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -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; + } } }