Isolate rich text notifications from other input changes
The step that would notify parent components of rich text state changes was stirred into the input's change handler, which leads to race which the parent is sometimes notified of the old rich text state instead of the new. Here we avoid this complication by using a separate path for sending the rich text state when we know we have updated it correctly.pull/21833/head
parent
3e6199c0f7
commit
ccd4dee0d2
|
@ -257,6 +257,8 @@ export default class MessageComposer extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onInputStateChanged(inputState) {
|
onInputStateChanged(inputState) {
|
||||||
|
// Merge the new input state with old to support partial updates
|
||||||
|
inputState = Object.assign({}, this.state.inputState, inputState);
|
||||||
this.setState({inputState});
|
this.setState({inputState});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -628,7 +628,6 @@ export default class MessageComposerInput extends React.Component {
|
||||||
}
|
}
|
||||||
const inputState = {
|
const inputState = {
|
||||||
marks: editorState.activeMarks,
|
marks: editorState.activeMarks,
|
||||||
isRichTextEnabled: this.state.isRichTextEnabled,
|
|
||||||
blockType,
|
blockType,
|
||||||
};
|
};
|
||||||
this.props.onInputStateChanged(inputState);
|
this.props.onInputStateChanged(inputState);
|
||||||
|
@ -698,8 +697,13 @@ export default class MessageComposerInput extends React.Component {
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState: this.createEditorState(enabled, editorState),
|
editorState: this.createEditorState(enabled, editorState),
|
||||||
isRichTextEnabled: enabled,
|
isRichTextEnabled: enabled,
|
||||||
}, ()=>{
|
}, () => {
|
||||||
this._editor.focus();
|
this._editor.focus();
|
||||||
|
if (this.props.onInputStateChanged) {
|
||||||
|
this.props.onInputStateChanged({
|
||||||
|
isRichTextEnabled: enabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SettingsStore.setValue("MessageComposerInput.isRichTextEnabled", null, SettingLevel.ACCOUNT, enabled);
|
SettingsStore.setValue("MessageComposerInput.isRichTextEnabled", null, SettingLevel.ACCOUNT, enabled);
|
||||||
|
|
Loading…
Reference in New Issue