nudge towards supporting formatting buttons in MD

pull/21833/head
Matthew Hodgson 2018-05-17 00:01:23 +01:00
parent 4eb6942211
commit ae208da805
1 changed files with 11 additions and 11 deletions

View File

@ -536,11 +536,12 @@ export default class MessageComposerInput extends React.Component {
this.enableRichtext(!this.state.isRichtextEnabled); this.enableRichtext(!this.state.isRichtextEnabled);
return true; return true;
} }
/*
let newState: ?EditorState = null; let newState: ?Value = null;
// Draft handles rich text mode commands by default but we need to do it ourselves for Markdown. // Draft handles rich text mode commands by default but we need to do it ourselves for Markdown.
if (this.state.isRichtextEnabled) { if (this.state.isRichtextEnabled) {
/*
// These are block types, not handled by RichUtils by default. // These are block types, not handled by RichUtils by default.
const blockCommands = ['code-block', 'blockquote', 'unordered-list-item', 'ordered-list-item']; const blockCommands = ['code-block', 'blockquote', 'unordered-list-item', 'ordered-list-item'];
const currentBlockType = RichUtils.getCurrentBlockType(this.state.editorState); const currentBlockType = RichUtils.getCurrentBlockType(this.state.editorState);
@ -563,7 +564,9 @@ export default class MessageComposerInput extends React.Component {
newState = RichUtils.toggleBlockType(this.state.editorState, currentBlockType); newState = RichUtils.toggleBlockType(this.state.editorState, currentBlockType);
} }
} }
*/
} else { } else {
/*
const contentState = this.state.editorState.getCurrentContent(); const contentState = this.state.editorState.getCurrentContent();
const multipleLinesSelected = RichText.hasMultiLineSelection(this.state.editorState); const multipleLinesSelected = RichText.hasMultiLineSelection(this.state.editorState);
@ -599,16 +602,17 @@ export default class MessageComposerInput extends React.Component {
'blockquote': -2, 'blockquote': -2,
}[command]; }[command];
// Returns a function that collapses a selectionState to its end and moves it by offset // Returns a function that collapses a selection to its end and moves it by offset
const collapseAndOffsetSelection = (selectionState, offset) => { const collapseAndOffsetSelection = (selection, offset) => {
const key = selectionState.getEndKey(); const key = selection.endKey();
return new SelectionState({ return new Range({
anchorKey: key, anchorOffset: offset, anchorKey: key, anchorOffset: offset,
focusKey: key, focusOffset: offset, focusKey: key, focusOffset: offset,
}); });
}; };
if (modifyFn) { if (modifyFn) {
const previousSelection = this.state.editorState.getSelection(); const previousSelection = this.state.editorState.getSelection();
const newContentState = RichText.modifyText(contentState, previousSelection, modifyFn); const newContentState = RichText.modifyText(contentState, previousSelection, modifyFn);
newState = EditorState.push( newState = EditorState.push(
@ -633,10 +637,6 @@ export default class MessageComposerInput extends React.Component {
} }
} }
if (newState == null) {
newState = RichUtils.handleKeyCommand(this.state.editorState, command);
}
if (newState != null) { if (newState != null) {
this.setState({editorState: newState}); this.setState({editorState: newState});
return true; return true;