@@ -528,16 +528,19 @@ export default class MessageComposerInput extends React.Component {
528
528
if ( this . state . isRichtextEnabled ) {
529
529
// These are block types, not handled by RichUtils by default.
530
530
const blockCommands = [ 'code-block' , 'blockquote' , 'unordered-list-item' , 'ordered-list-item' ] ;
531
+ const currentBlockType = RichUtils . getCurrentBlockType ( this . state . editorState ) ;
531
532
532
533
if ( blockCommands . includes ( command ) ) {
533
- this . setState ( {
534
- editorState : RichUtils . toggleBlockType ( this . state . editorState , command ) ,
535
- } ) ;
534
+ newState = RichUtils . toggleBlockType ( this . state . editorState , command ) ;
536
535
} else if ( command === 'strike' ) {
537
536
// this is the only inline style not handled by Draft by default
538
- this . setState ( {
539
- editorState : RichUtils . toggleInlineStyle ( this . state . editorState , 'STRIKETHROUGH' ) ,
540
- } ) ;
537
+ newState = RichUtils . toggleInlineStyle ( this . state . editorState , 'STRIKETHROUGH' ) ;
538
+ } else if ( command === 'backspace' && currentBlockType !== 'unstyled' ) {
539
+ const currentStartOffset = this . state . editorState . getSelection ( ) . getStartOffset ( ) ;
540
+ if ( currentStartOffset === 0 ) {
541
+ // Toggle current block type (setting it to 'unstyled')
542
+ newState = RichUtils . toggleBlockType ( this . state . editorState , currentBlockType ) ;
543
+ }
541
544
}
542
545
} else {
543
546
let contentState = this . state . editorState . getCurrentContent ( ) ;
@@ -644,6 +647,7 @@ export default class MessageComposerInput extends React.Component {
644
647
// By returning false, we allow the default draft-js key binding to occur,
645
648
// which in this case invokes "split-block". This creates a new block of the
646
649
// same type, allowing the user to delete it with backspace.
650
+ // See handleKeyCommand (when command === 'backspace')
647
651
return false ;
648
652
}
649
653
0 commit comments