File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import insertEmptyBlock from './modifiers/insertEmptyBlock';
1313import handleLink from './modifiers/handleLink' ;
1414import handleImage from './modifiers/handleImage' ;
1515import leaveList from './modifiers/leaveList' ;
16+ import insertText from './modifiers/insertText' ;
1617import createLinkDecorator from './decorators/link' ;
1718import createImageDecorator from './decorators/image' ;
1819
@@ -51,6 +52,9 @@ const createMarkdownShortcutsPlugin = (config = {}) => {
5152 ( ev . ctrlKey || ev . shiftKey || ev . metaKey || ev . altKey || / ^ h e a d e r - / . test ( type ) ) ) {
5253 newEditorState = insertEmptyBlock ( editorState ) ;
5354 }
55+ if ( newEditorState === editorState && type === 'code-block' ) {
56+ newEditorState = insertText ( editorState , '\n' ) ;
57+ }
5458 if ( newEditorState === editorState ) {
5559 newEditorState = handleNewCodeBlock ( editorState ) ;
5660 }
Original file line number Diff line number Diff line change 1+ import { EditorState , Modifier } from 'draft-js' ;
2+
3+ const insertText = ( editorState , text ) => {
4+ const selection = editorState . getSelection ( ) ;
5+ const content = editorState . getCurrentContent ( ) ;
6+ const newContentState = Modifier . insertText (
7+ content ,
8+ selection ,
9+ text ,
10+ editorState . getCurrentInlineStyle ( )
11+ ) ;
12+ return EditorState . push (
13+ editorState ,
14+ newContentState ,
15+ 'insert-fragment'
16+ ) ;
17+ } ;
18+
19+ export default insertText ;
You can’t perform that action at this time.
0 commit comments