Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Mar 30, 2019
1 parent a9cccaa commit c08c0b5
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,30 +928,23 @@ export class RichText extends Component {
const { tagName, value, isSelected } = this.props;
const record = this.getRecord();

if (
// Check if the content changed.
let shouldReapply = (
tagName === prevProps.tagName &&
value !== prevProps.value &&
value !== this.savedContent
) {
if ( ! isSelected ) {
delete record.start;
delete record.end;
}

this.applyRecord( record );
} else if ( isSelected && ! prevProps.isSelected && (
this.savedSelectionStart !== record.start ||
this.savedSelectionEnd !== record.end
) ) {
this.applyRecord( record );
}
);

this.savedContent = value;
this.savedSelectionStart = record.start;
this.savedSelectionEnd = record.end;
// Check if the selection changed.
shouldReapply = shouldReapply || (
isSelected && ! prevProps.isSelected && (
this.savedSelectionStart !== record.start ||
this.savedSelectionEnd !== record.end
)
);

// If any format props update, reapply value.
const shouldReapply = Object.keys( this.props ).some( ( name ) => {
// Check if any format props changed.
shouldReapply = shouldReapply || Object.keys( this.props ).some( ( name ) => {
if ( name.indexOf( 'format_' ) !== 0 ) {
return false;
}
Expand All @@ -974,6 +967,10 @@ export class RichText extends Component {

this.applyRecord( record );
}

this.savedContent = value;
this.savedSelectionStart = record.start;
this.savedSelectionEnd = record.end;
}

/**
Expand Down

0 comments on commit c08c0b5

Please sign in to comment.