-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #635 from WordPress/remove/editable-split-settimeout
Maintain Editable focus synchronously when splitting blocks
- Loading branch information
Showing
3 changed files
with
76 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
export default class TinyMCE extends wp.element.Component { | ||
componentDidMount() { | ||
tinymce.init( { | ||
target: this.editorNode, | ||
theme: false, | ||
inline: true, | ||
toolbar: false, | ||
browser_spellcheck: true, | ||
entity_encoding: 'raw', | ||
convert_urls: false, | ||
setup: this.props.onSetup, | ||
formats: { | ||
strikethrough: { inline: 'del' } | ||
} | ||
} ); | ||
|
||
if ( this.props.focus ) { | ||
this.editorNode.focus(); | ||
} | ||
} | ||
|
||
shouldComponentUpdate() { | ||
// We must prevent rerenders because TinyMCE will modify the DOM, thus | ||
// breaking React's ability to reconcile changes. | ||
// | ||
// See: https://github.com/facebook/react/issues/6802 | ||
return false; | ||
} | ||
|
||
render() { | ||
const { tagName = 'div', style, className, defaultValue } = this.props; | ||
|
||
// If a default value is provided, render it into the DOM even before | ||
// TinyMCE finishes initializing. This avoids a short delay by allowing | ||
// us to show and focus the content before it's truly ready to edit. | ||
let children; | ||
if ( defaultValue ) { | ||
children = wp.element.Children.toArray( defaultValue ); | ||
} | ||
|
||
return wp.element.createElement( tagName, { | ||
ref: ( node ) => this.editorNode = node, | ||
contentEditable: true, | ||
suppressContentEditableWarning: true, | ||
style, | ||
className | ||
}, children ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters