浏览代码

Aligned code to changes in DocumentSelection API.

Maciej Bukowski 7 年之前
父节点
当前提交
515c364f7e
共有 2 个文件被更改,包括 18 次插入7 次删除
  1. 10 5
      packages/ckeditor5-heading/tests/headingcommand.js
  2. 8 2
      packages/ckeditor5-heading/tests/integration.js

+ 10 - 5
packages/ckeditor5-heading/tests/headingcommand.js

@@ -63,8 +63,13 @@ describe( 'HeadingCommand', () => {
 			it( `equals ${ modelElement } when collapsed selection is placed inside ${ modelElement } element`, () => {
 				setData( model, `<${ modelElement }>foobar</${ modelElement }>` );
 				const element = root.getChild( 0 );
-				document.selection.addRange( Range.createFromParentsAndOffsets( element, 3, element, 3 ) );
-
+				model.change( writer => {
+					const ranges = [
+						...model.document.selection.getRanges(),
+						Range.createFromParentsAndOffsets( element, 3, element, 3 )
+					];
+					writer.setSelection( ranges );
+				} );
 				expect( commands[ modelElement ].value ).to.be.true;
 			} );
 
@@ -78,8 +83,8 @@ describe( 'HeadingCommand', () => {
 				setData( model, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
 				const element = document.getRoot().getChild( 1 );
 
-				model.change( () => {
-					document.selection.setRanges( [ Range.createIn( element ) ] );
+				model.change( writer => {
+					writer.setSelection( Range.createIn( element ) );
 				} );
 
 				expect( commands[ modelElement ].value ).to.be.false;
@@ -91,7 +96,7 @@ describe( 'HeadingCommand', () => {
 				const element = document.getRoot().getChild( 1 );
 
 				// Purposely not putting it in `model.change` to update command manually.
-				document.selection.setRanges( [ Range.createIn( element ) ] );
+				model.document.selection._setTo( Range.createIn( element ) );
 
 				expect( command.value ).to.be.true;
 				command.refresh();

+ 8 - 2
packages/ckeditor5-heading/tests/integration.js

@@ -43,7 +43,10 @@ describe( 'Heading integration', () => {
 	describe( 'with the enter key', () => {
 		it( 'should make the "enter" command insert a default heading block if the selection ended at the end of a heading block', () => {
 			editor.setData( '<h2>foobar</h2>' );
-			doc.selection.setCollapsedAt( doc.getRoot().getChild( 0 ), 'end' );
+
+			model.change( writer => {
+				writer.setSelection( doc.getRoot().getChild( 0 ), 'end' );
+			} );
 
 			editor.execute( 'enter' );
 
@@ -53,7 +56,10 @@ describe( 'Heading integration', () => {
 		it( 'should not alter the "enter" command if selection not ended at the end of a heading block', () => {
 			// This test is to fill code coverage.
 			editor.setData( '<h2>foobar</h2>' );
-			doc.selection.setCollapsedAt( doc.getRoot().getChild( 0 ), 3 );
+
+			model.change( writer => {
+				writer.setSelection( doc.getRoot().getChild( 0 ), 3 );
+			} );
 
 			editor.execute( 'enter' );