Skip to content

Commit

Permalink
[Mobile] native mobile release v1.5.1 (#15734)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hypest authored May 20, 2019
1 parent 9d56b8b commit d2a164b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
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

0 comments on commit d2a164b

Please sign in to comment.