Skip to content

Commit

Permalink
RichText: Only set selection on selected RichText
Browse files Browse the repository at this point in the history
When `shouldReapply` was true we would set `start` and `end` on the
record. This is valid, but should only happen when the `RichText` is
already selected. If it is not selected `toDOM` would create a browser
selection and the browser would select that `RichText`. Resulting in
the last `RichText` the user touched always being focused when
applying annotations.
  • Loading branch information
atimmer committed Dec 9, 2018
1 parent 29694f1 commit cd76538
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,14 @@ export class RichText extends Component {
if ( shouldReapply ) {
const record = this.formatToValue( value );

// Maintain the previous selection:
record.start = this.state.start;
record.end = this.state.end;
// If we always specify this the selection will go to this RichText
// regardless whether is is actually the currently selected one.
// So check if this RichText is the selected one.
if ( this.props.isSelected ) {
// Maintain the previous selection:
record.start = this.state.start;
record.end = this.state.end;
}

this.applyRecord( record );
}
Expand Down

0 comments on commit cd76538

Please sign in to comment.