Skip to content

Commit

Permalink
Fix mobile quotes insertion and removal of empty lines (#16013)
Browse files Browse the repository at this point in the history
* Make sure selection is not over length of text.

* Replicate web behaviour for onSplit detection.
  • Loading branch information
SergioEstevao committed Jun 6, 2019
1 parent dfed30a commit 6b2e834
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/block-editor/src/components/rich-text/index.native.js
Expand Up @@ -165,7 +165,7 @@ export class RichText extends Component {
* @return {Object} A RichText value with formats and selection.
*/
createRecord() {
return {
const value = {
start: this.selectionStart,
end: this.selectionEnd,
...create( {
Expand All @@ -175,6 +175,9 @@ export class RichText extends Component {
multilineWrapperTags: this.multilineWrapperTags,
} ),
};
const start = Math.min( this.selectionStart, value.text.length );
const end = Math.min( this.selectionEnd, value.text.length );
return { ...value, start, end };
}

/**
Expand Down Expand Up @@ -347,15 +350,15 @@ export class RichText extends Component {
this.lastEventCount = event.nativeEvent.eventCount;
this.comesFromAztec = true;
this.firedAfterTextChanged = event.nativeEvent.firedAfterTextChanged;

const { onReplace, onSplit } = this.props;
const canSplit = onReplace && onSplit;
const currentRecord = this.createRecord();

if ( this.multilineTag ) {
if ( event.shiftKey ) {
this.needsSelectionUpdate = true;
const insertedLineBreak = { ...insert( currentRecord, '\n' ) };
this.onFormatChange( insertedLineBreak );
} else if ( this.onSplit && isEmptyLine( currentRecord ) ) {
} else if ( canSplit && isEmptyLine( currentRecord ) ) {
this.onSplit( currentRecord );
} else {
this.needsSelectionUpdate = true;
Expand Down

0 comments on commit 6b2e834

Please sign in to comment.