Skip to content

Commit

Permalink
RichText: selectionChange: bind on focus, unbind on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 30, 2018
1 parent 4178f2d commit dd331b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/editor/src/components/rich-text/index.js
Expand Up @@ -93,6 +93,7 @@ export class RichText extends Component {

this.onSetup = this.onSetup.bind( this );
this.onFocus = this.onFocus.bind( this );
this.onBlur = this.onBlur.bind( this );
this.onChange = this.onChange.bind( this );
this.onDeleteKeyDown = this.onDeleteKeyDown.bind( this );
this.onKeyDown = this.onKeyDown.bind( this );
Expand Down Expand Up @@ -129,14 +130,6 @@ export class RichText extends Component {
this.lastHistoryValue = value;
}

componentDidMount() {
document.addEventListener( 'selectionchange', this.onSelectionChange );
}

componentWillUnmount() {
document.removeEventListener( 'selectionchange', this.onSelectionChange );
}

setRef( node ) {
this.editableRef = node;
}
Expand Down Expand Up @@ -354,6 +347,12 @@ export class RichText extends Component {
if ( unstableOnFocus ) {
unstableOnFocus();
}

document.addEventListener( 'selectionchange', this.onSelectionChange );
}

onBlur() {
document.removeEventListener( 'selectionchange', this.onSelectionChange );
}

/**
Expand Down Expand Up @@ -891,6 +890,7 @@ export class RichText extends Component {
onCompositionEnd={ this.onCompositionEnd }
onKeyDown={ this.onKeyDown }
onFocus={ this.onFocus }
onBlur={ this.onBlur }
multilineTag={ this.multilineTag }
multilineWrapperTags={ this.multilineWrapperTags }
setRef={ this.setRef }
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/rich-text/tinymce.js
Expand Up @@ -350,6 +350,7 @@ export default class TinyMCE extends Component {
onInput,
onKeyDown,
onCompositionEnd,
onBlur,
} = this.props;

/*
Expand Down Expand Up @@ -377,6 +378,7 @@ export default class TinyMCE extends Component {
onPaste,
onInput,
onFocus: this.onFocus,
onBlur,
onKeyDown,
onCompositionEnd,
} );
Expand Down

0 comments on commit dd331b3

Please sign in to comment.