Merge pull request #1258 from matrix-org/luke/feature-rte-enter-to-toggle-empty-block
Interpret a `split-block` as format toggle for an empty block
This commit is contained in:
commit
8fd0ced215
1 changed files with 7 additions and 1 deletions
|
@ -502,12 +502,18 @@ export default class MessageComposerInput extends React.Component {
|
||||||
// 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);
|
||||||
|
|
||||||
|
const shouldToggleBlockFormat = (
|
||||||
|
command === 'backspace' ||
|
||||||
|
command === 'split-block'
|
||||||
|
) && currentBlockType !== 'unstyled';
|
||||||
|
|
||||||
if (blockCommands.includes(command)) {
|
if (blockCommands.includes(command)) {
|
||||||
newState = RichUtils.toggleBlockType(this.state.editorState, command);
|
newState = RichUtils.toggleBlockType(this.state.editorState, command);
|
||||||
} else if (command === 'strike') {
|
} else if (command === 'strike') {
|
||||||
// this is the only inline style not handled by Draft by default
|
// this is the only inline style not handled by Draft by default
|
||||||
newState = RichUtils.toggleInlineStyle(this.state.editorState, 'STRIKETHROUGH');
|
newState = RichUtils.toggleInlineStyle(this.state.editorState, 'STRIKETHROUGH');
|
||||||
} else if (command === 'backspace' && currentBlockType !== 'unstyled') {
|
} else if (shouldToggleBlockFormat) {
|
||||||
const currentStartOffset = this.state.editorState.getSelection().getStartOffset();
|
const currentStartOffset = this.state.editorState.getSelection().getStartOffset();
|
||||||
if (currentStartOffset === 0) {
|
if (currentStartOffset === 0) {
|
||||||
// Toggle current block type (setting it to 'unstyled')
|
// Toggle current block type (setting it to 'unstyled')
|
||||||
|
|
Loading…
Reference in a new issue