Skip to content

Commit

Permalink
Temporary fix for cursor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabriskie committed Jul 29, 2017
1 parent 05a6bc3 commit a25b204
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
36 changes: 18 additions & 18 deletions lib/components/TinyMCE.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,24 @@ const TinyMCE = React.createClass({

componentDidMount() {
const config = clone(this.props.config);
this._init(config);
this._init(config, this.props.content);
},

componentWillReceiveProps(nextProps) {
if (!isEqual(this.props.id, nextProps.id)) {
this.id = nextProps.id;
}
if (!isEqual(this.props.config, nextProps.config) || !isEqual(this.props.id, nextProps.id)) {
this.id = nextProps.id;
this._init(clone(nextProps.config), nextProps.content);
return;
}

const editor = tinymce.EditorManager.get(this.id);
if (!isEqual(editor.getContent({format: 'raw'}), nextProps.content)) {
editor.setContent(nextProps.content);

editor.selection.select(editor.getBody(), true);
editor.selection.collapse(false);
}
// TODO: This will fix problems with keeping internal state, but causes problems with cursor placement
// if (!isEqual(this.props.content, nextProps.content)) {
// const editor = tinymce.EditorManager.get(this.id);
// editor.setContent(nextProps.content);
//
// editor.selection.select(editor.getBody(), true);
// editor.selection.collapse(false);
// }
},

shouldComponentUpdate(nextProps) {
Expand Down Expand Up @@ -114,17 +113,18 @@ const TinyMCE = React.createClass({

config.selector = '#' + this.id;
config.setup = (editor) => {
EVENTS.forEach((event, index) => {
const handler = this.props[HANDLER_NAMES[index]];
if (typeof handler !== 'function') return;
editor.on(event, (e) => {
// native DOM events don't have access to the editor so we pass it here
handler(e, editor);
EVENTS.forEach((eventType, index) => {
editor.on(eventType, (e) => {
const handler = this.props[HANDLER_NAMES[index]];
if (typeof handler === 'function') {
// native DOM events don't have access to the editor so we pass it here
handler(e, editor);
}
});
});
// need to set content here because the textarea will still have the
// old `this.props.content`
if (content) {
if (typeof content !== 'undefined') {
editor.on('init', () => {
editor.setContent(content);
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"react-dom": "^0.14.0 || ^15.0.0"
},
"devDependencies": {
"rackt-cli": "^0.5.3",
"rackt-cli": "^0.8.0",
"react": "^15.0.0",
"react-dom": "^15.0.0"
},
"dependencies": {
"lodash": ">=4.0.0"
}
}
}

0 comments on commit a25b204

Please sign in to comment.