@@ -31,6 +31,43 @@ describe("selection", () => {
3131 ] ) ,
3232 ]
3333
34+ it ( "inserts a block if there is none left, with selection on it" , ( ) => {
35+ let editorState = EditorState . createWithContent (
36+ convertFromRaw ( {
37+ entityMap : { } ,
38+ blocks : [
39+ {
40+ key : "f8beh" ,
41+ text : "test" ,
42+ depth : 3 ,
43+ } ,
44+ ] ,
45+ } ) ,
46+ )
47+
48+ const content = editorState . getCurrentContent ( )
49+ const nextContent = filters . reduce ( ( c , filter ) => filter ( c ) , content )
50+ const nextState = applyContentWithSelection (
51+ editorState ,
52+ content ,
53+ nextContent ,
54+ )
55+ const block = nextState . getCurrentContent ( ) . getFirstBlock ( )
56+
57+ expect ( block . toJS ( ) ) . toMatchObject ( {
58+ text : "" ,
59+ type : "unstyled" ,
60+ depth : 0 ,
61+ } )
62+
63+ expect ( nextState . getSelection ( ) . toJS ( ) ) . toMatchObject ( {
64+ anchorKey : block . getKey ( ) ,
65+ anchorOffset : 0 ,
66+ focusKey : block . getKey ( ) ,
67+ focusOffset : 0 ,
68+ } )
69+ } )
70+
3471 it ( "does not change selection if valid" , ( ) => {
3572 let editorState = EditorState . createWithContent (
3673 convertFromRaw ( {
@@ -134,45 +171,6 @@ describe("selection", () => {
134171 } )
135172 } )
136173
137- it ( "does not change selection if it cannot be moved elsewhere" , ( ) => {
138- let editorState = EditorState . createWithContent (
139- convertFromRaw ( {
140- entityMap : { } ,
141- blocks : [
142- {
143- key : "f8beh" ,
144- text : "test" ,
145- depth : 3 ,
146- } ,
147- ] ,
148- } ) ,
149- )
150- editorState = EditorState . acceptSelection (
151- editorState ,
152- editorState . getSelection ( ) . merge ( {
153- anchorKey : "f8beh" ,
154- focusKey : "f8beh" ,
155- anchorOffset : 4 ,
156- focusOffset : 4 ,
157- } ) ,
158- )
159-
160- const content = editorState . getCurrentContent ( )
161- const nextContent = filters . reduce ( ( c , filter ) => filter ( c ) , content )
162- const nextState = applyContentWithSelection (
163- editorState ,
164- content ,
165- nextContent ,
166- )
167-
168- expect ( nextState . getSelection ( ) . toJS ( ) ) . toMatchObject ( {
169- anchorKey : "f8beh" ,
170- anchorOffset : 4 ,
171- focusKey : "f8beh" ,
172- focusOffset : 4 ,
173- } )
174- } )
175-
176174 it ( "works for the last block" , ( ) => {
177175 let editorState = EditorState . createWithContent (
178176 convertFromRaw ( {
0 commit comments