mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 14:05:04 +08:00
Fix highlighting behaviour on switch
Hopefully made the code a little bit clearer.
This commit is contained in:
parent
a5a3e4e915
commit
8f45f168d5
@ -97,13 +97,16 @@ export default class MessageComposerInput extends React.Component {
|
|||||||
* - whether we've got rich text mode enabled
|
* - whether we've got rich text mode enabled
|
||||||
* - contentState was passed in
|
* - contentState was passed in
|
||||||
*/
|
*/
|
||||||
createEditorState(contentState: ?ContentState): EditorState {
|
createEditorState(richText: boolean, contentState: ?ContentState): EditorState {
|
||||||
let func = contentState ? EditorState.createWithContent : EditorState.createEmpty;
|
let decorators = richText ? RichText.getScopedRTDecorators(this.props) :
|
||||||
const decoratorFunc = this.state.isRichtextEnabled ? RichText.getScopedRTDecorators :
|
RichText.getScopedMDDecorators(this.props),
|
||||||
RichText.getScopedMDDecorators;
|
compositeDecorator = new CompositeDecorator(decorators);
|
||||||
let args = contentState ? [contentState] : [];
|
|
||||||
args.push(new CompositeDecorator(decoratorFunc(this.props)));
|
if (contentState) {
|
||||||
return func(...args);
|
return EditorState.createWithContent(contentState, compositeDecorator);
|
||||||
|
} else {
|
||||||
|
return EditorState.createEmpty(compositeDecorator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
@ -194,7 +197,7 @@ export default class MessageComposerInput extends React.Component {
|
|||||||
if (contentJSON) {
|
if (contentJSON) {
|
||||||
let content = convertFromRaw(JSON.parse(contentJSON));
|
let content = convertFromRaw(JSON.parse(contentJSON));
|
||||||
component.setState({
|
component.setState({
|
||||||
editorState: component.createEditorState(content)
|
editorState: component.createEditorState(this.state.isRichtextEnabled, content)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,16 +344,16 @@ export default class MessageComposerInput extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enableRichtext(enabled: boolean) {
|
enableRichtext(enabled: boolean) {
|
||||||
if(enabled) {
|
if (enabled) {
|
||||||
let html = mdownToHtml(this.state.editorState.getCurrentContent().getPlainText());
|
let html = mdownToHtml(this.state.editorState.getCurrentContent().getPlainText());
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState: this.createEditorState(RichText.HTMLtoContentState(html))
|
editorState: this.createEditorState(enabled, RichText.HTMLtoContentState(html))
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let markdown = stateToMarkdown(this.state.editorState.getCurrentContent());
|
let markdown = stateToMarkdown(this.state.editorState.getCurrentContent()),
|
||||||
let contentState = ContentState.createFromText(markdown);
|
contentState = ContentState.createFromText(markdown);
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState: this.createEditorState(contentState)
|
editorState: this.createEditorState(enabled, contentState)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user