From 50057fc750b33fd7ba99844e49c0c9dc1cf05152 Mon Sep 17 00:00:00 2001 From: Anton Timmermans Date: Wed, 21 Nov 2018 17:24:38 +0100 Subject: [PATCH] RichText: Only set selection on selected RichText 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. --- packages/editor/src/components/rich-text/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index 2033ce14cb8f7d..1729863ca8ab1c 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -713,9 +713,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 ); }