@@ -32,44 +32,49 @@ const handleBlockType = (editorState, character) => {
3232 ""
3333 ) ;
3434 const blockType = RichUtils . getCurrentBlockType ( editorState ) ;
35- for ( let i = 1 ; i <= 6 ; i += 1 ) {
36- if ( line . indexOf ( `${ sharps ( i ) } ` ) === 0 ) {
35+
36+ if ( blockType === "unstyled" || blockType === "paragraph" ) {
37+ for ( let i = 1 ; i <= 6 ; i += 1 ) {
38+ if ( line . indexOf ( `${ sharps ( i ) } ` ) === 0 ) {
39+ return changeCurrentBlockType (
40+ editorState ,
41+ blockTypes [ i ] ,
42+ line . replace ( / ^ # + \s / , "" )
43+ ) ;
44+ }
45+ }
46+ let matchArr = line . match ( / ^ [ * - ] ( .* ) $ / ) ;
47+ if ( matchArr ) {
3748 return changeCurrentBlockType (
3849 editorState ,
39- blockTypes [ i ] ,
40- line . replace ( / ^ # + \s / , "" )
50+ "unordered-list-item" ,
51+ matchArr [ 1 ]
52+ ) ;
53+ }
54+ matchArr = line . match ( / ^ [ \d ] \. ( .* ) $ / ) ;
55+ if ( matchArr ) {
56+ return changeCurrentBlockType (
57+ editorState ,
58+ "ordered-list-item" ,
59+ matchArr [ 1 ]
60+ ) ;
61+ }
62+ matchArr = line . match ( / ^ > ( .* ) $ / ) ;
63+ if ( matchArr ) {
64+ return changeCurrentBlockType ( editorState , "blockquote" , matchArr [ 1 ] ) ;
65+ }
66+ } else if ( blockType === "unordered-list-item" ) {
67+ let matchArr = line . match ( / ^ \[ ( [ x ] ) ] ( .* ) $ / i) ;
68+ if ( matchArr ) {
69+ return changeCurrentBlockType (
70+ editorState ,
71+ CHECKABLE_LIST_ITEM ,
72+ matchArr [ 2 ] ,
73+ { checked : matchArr [ 1 ] !== " " }
4174 ) ;
4275 }
4376 }
44- let matchArr = line . match ( / ^ [ * - ] ( .* ) $ / ) ;
45- if ( matchArr ) {
46- return changeCurrentBlockType (
47- editorState ,
48- "unordered-list-item" ,
49- matchArr [ 1 ]
50- ) ;
51- }
52- matchArr = line . match ( / ^ [ \d ] \. ( .* ) $ / ) ;
53- if ( matchArr ) {
54- return changeCurrentBlockType (
55- editorState ,
56- "ordered-list-item" ,
57- matchArr [ 1 ]
58- ) ;
59- }
60- matchArr = line . match ( / ^ > ( .* ) $ / ) ;
61- if ( matchArr ) {
62- return changeCurrentBlockType ( editorState , "blockquote" , matchArr [ 1 ] ) ;
63- }
64- matchArr = line . match ( / ^ \[ ( [ x ] ) ] ( .* ) $ / i) ;
65- if ( matchArr && blockType === "unordered-list-item" ) {
66- return changeCurrentBlockType (
67- editorState ,
68- CHECKABLE_LIST_ITEM ,
69- matchArr [ 2 ] ,
70- { checked : matchArr [ 1 ] !== " " }
71- ) ;
72- }
77+
7378 return editorState ;
7479} ;
7580
0 commit comments