@@ -6,12 +6,19 @@ import {
6
6
CHECKABLE_LIST_ITEM ,
7
7
} from "draft-js-checkable-list-item" ;
8
8
9
- import { Map } from "immutable" ;
10
- import { getDefaultKeyBinding , Modifier , EditorState } from "draft-js" ;
9
+ import { Map , OrderedSet } from "immutable" ;
10
+ import {
11
+ getDefaultKeyBinding ,
12
+ Modifier ,
13
+ EditorState ,
14
+ RichUtils ,
15
+ DefaultDraftInlineStyle ,
16
+ } from "draft-js" ;
11
17
import adjustBlockDepth from "./modifiers/adjustBlockDepth" ;
12
18
import handleBlockType from "./modifiers/handleBlockType" ;
13
19
import handleInlineStyle from "./modifiers/handleInlineStyle" ;
14
20
import handleNewCodeBlock from "./modifiers/handleNewCodeBlock" ;
21
+ import resetInlineStyle from "./modifiers/resetInlineStyle" ;
15
22
import insertEmptyBlock from "./modifiers/insertEmptyBlock" ;
16
23
import handleLink from "./modifiers/handleLink" ;
17
24
import handleImage from "./modifiers/handleImage" ;
@@ -152,31 +159,24 @@ const createMarkdownPlugin = (config = {}) => {
152
159
}
153
160
return "not-handled" ;
154
161
} ,
155
- keyBindingFn ( ev , { getEditorState, setEditorState } ) {
156
- if ( ev . which === 13 ) {
157
- const editorState = getEditorState ( ) ;
158
- let newEditorState = checkReturnForState ( editorState , ev ) ;
159
- if ( editorState !== newEditorState ) {
160
- setEditorState ( newEditorState ) ;
161
- return "handled" ;
162
- }
162
+ handleReturn ( ev , editorState , { setEditorState } ) {
163
+ let newEditorState = checkReturnForState ( editorState , ev ) ;
164
+ let selection = newEditorState . getSelection ( ) ;
163
165
164
- newEditorState = checkCharacterForState ( editorState , "" ) ;
165
- if ( ! inCodeBlock ( editorState ) && editorState !== newEditorState ) {
166
- const contentState = Modifier . splitBlock (
167
- newEditorState . getCurrentContent ( ) ,
168
- newEditorState . getSelection ( )
169
- ) ;
166
+ newEditorState = checkCharacterForState ( newEditorState , "" ) ;
167
+ let content = newEditorState . getCurrentContent ( ) ;
170
168
171
- setEditorState (
172
- EditorState . push ( newEditorState , contentState , "split-block" )
173
- ) ;
169
+ content = Modifier . splitBlock ( content , selection ) ;
174
170
175
- return "handled" ;
176
- }
177
- }
171
+ setEditorState (
172
+ EditorState . push (
173
+ resetInlineStyle ( newEditorState ) ,
174
+ content ,
175
+ "split-block"
176
+ )
177
+ ) ;
178
178
179
- return getDefaultKeyBinding ( ev ) ;
179
+ return "handled" ;
180
180
} ,
181
181
handleBeforeInput ( character , editorState , { setEditorState } ) {
182
182
if ( character !== " " ) {
0 commit comments