@@ -815,7 +815,16 @@ test('#toggleSection changes multiple sections to and from tag name', (assert) =
815815 assert . equal ( post . sections . head . tagName , 'p' ) ;
816816 assert . equal ( post . sections . tail . tagName , 'p' ) ;
817817
818- assert . positionIsEqual ( mockEditor . _renderedRange . head , post . sections . head . headPosition ( ) ) ;
818+ assert . positionIsEqual (
819+ mockEditor . _renderedRange . head ,
820+ post . sections . head . toPosition ( 2 ) ,
821+ 'Maintains the selection'
822+ ) ;
823+ assert . positionIsEqual (
824+ mockEditor . _renderedRange . tail ,
825+ post . sections . tail . toPosition ( 2 ) ,
826+ 'Maintains the selection'
827+ ) ;
819828} ) ;
820829
821830test ( '#toggleSection skips over non-markerable sections' , ( assert ) => {
@@ -1301,6 +1310,33 @@ test('#toggleSection joins contiguous list items', (assert) => {
13011310 [ 'abc' , '123' , 'def' ] ) ;
13021311} ) ;
13031312
1313+ test ( '#toggleSection maintains the selection when the sections in the selected range are still there' , ( assert ) => {
1314+ let post = Helpers . postAbstract . build ( ( { post, markupSection, marker} ) => {
1315+ return post ( [
1316+ markupSection ( 'p' , [ marker ( 'abc' ) ] )
1317+ ] ) ;
1318+ } ) ;
1319+
1320+ mockEditor = renderBuiltAbstract ( post , mockEditor ) ;
1321+ const range = Range . create ( post . sections . head , 1 ,
1322+ post . sections . head , 2 ) ;
1323+
1324+ postEditor = new PostEditor ( mockEditor ) ;
1325+ postEditor . toggleSection ( 'h1' , range ) ;
1326+ postEditor . complete ( ) ;
1327+
1328+ assert . positionIsEqual (
1329+ mockEditor . _renderedRange . head ,
1330+ post . sections . head . toPosition ( 1 ) ,
1331+ 'Maintains the selection'
1332+ ) ;
1333+ assert . positionIsEqual (
1334+ mockEditor . _renderedRange . tail ,
1335+ post . sections . tail . toPosition ( 2 ) ,
1336+ 'Maintains the selection'
1337+ ) ;
1338+ } ) ;
1339+
13041340test ( '#toggleMarkup when cursor is in non-markerable does nothing' , ( assert ) => {
13051341 editor = buildEditorWithMobiledoc (
13061342 ( { post, markupSection, marker, cardSection} ) => {
0 commit comments