Skip to content

Commit

Permalink
RichText: remove selection change listener during composition (#14449)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and youknowriad committed Mar 20, 2019
1 parent 462e9fa commit 4f4a66d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
32 changes: 7 additions & 25 deletions packages/block-editor/src/components/rich-text/editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BACKSPACE, DELETE } from '@wordpress/keycodes';
/**
* Internal dependencies
*/
import { diffAriaProps, pickAriaProps } from './aria';
import { diffAriaProps } from './aria';

/**
* Browser dependencies
Expand Down Expand Up @@ -137,10 +137,7 @@ export default class Editable extends Component {

bindEditorNode( editorNode ) {
this.editorNode = editorNode;

if ( this.props.setRef ) {
this.props.setRef( editorNode );
}
this.props.setRef( editorNode );

if ( IS_IE ) {
if ( editorNode ) {
Expand All @@ -154,44 +151,29 @@ export default class Editable extends Component {
}

render() {
const ariaProps = pickAriaProps( this.props );
const {
tagName = 'div',
style,
record,
valueToEditableHTML,
className,
isPlaceholderVisible,
onPaste,
onInput,
onKeyDown,
onCompositionEnd,
onFocus,
onBlur,
onMouseDown,
onTouchStart,
...remainingProps
} = this.props;

ariaProps.role = 'textbox';
ariaProps[ 'aria-multiline' ] = true;
delete remainingProps.setRef;

return createElement( tagName, {
...ariaProps,
role: 'textbox',
'aria-multiline': true,
className: classnames( className, CLASS_NAME ),
contentEditable: true,
[ IS_PLACEHOLDER_VISIBLE_ATTR_NAME ]: isPlaceholderVisible,
ref: this.bindEditorNode,
style,
suppressContentEditableWarning: true,
dangerouslySetInnerHTML: { __html: valueToEditableHTML( record ) },
onPaste,
onInput,
onFocus,
onBlur,
onKeyDown,
onCompositionEnd,
onMouseDown,
onTouchStart,
...remainingProps,
} );
}
}
6 changes: 4 additions & 2 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ export class RichText extends Component {
// Browsers setting `isComposing` to `true` will usually emit a final
// `input` event when the characters are composed.
if ( event && event.nativeEvent.isComposing ) {
// Also don't update any selection.
document.removeEventListener( 'selectionchange', this.onSelectionChange );
return;
}

Expand Down Expand Up @@ -444,6 +446,8 @@ export class RichText extends Component {
// Ensure the value is up-to-date for browsers that don't emit a final
// input event after composition.
this.onInput();
// Tracking selection changes can be resumed.
document.addEventListener( 'selectionchange', this.onSelectionChange );
}

/**
Expand Down Expand Up @@ -1114,8 +1118,6 @@ export class RichText extends Component {
onBlur={ this.onBlur }
onMouseDown={ this.onPointerDown }
onTouchStart={ this.onPointerDown }
multilineTag={ this.multilineTag }
multilineWrapperTags={ this.multilineWrapperTags }
setRef={ this.setRef }
/>
{ isPlaceholderVisible &&
Expand Down

0 comments on commit 4f4a66d

Please sign in to comment.