Browse Source

Aligned code to the changes in DocumentSelection API.

Maciej Gołaszewski 7 years ago
parent
commit
60f41e3161

+ 2 - 2
packages/ckeditor5-font/src/fontcommand.js

@@ -71,9 +71,9 @@ export default class FontCommand extends Command {
 		model.change( writer => {
 			if ( selection.isCollapsed ) {
 				if ( value ) {
-					selection.setAttribute( this.attributeKey, value );
+					writer.setSelectionAttribute( this.attributeKey, value );
 				} else {
-					selection.removeAttribute( this.attributeKey );
+					writer.removeSelectionAttribute( this.attributeKey );
 				}
 			} else {
 				const ranges = model.schema.getValidRanges( selection.getRanges(), this.attributeKey );

+ 7 - 7
packages/ckeditor5-font/tests/fontcommand.js

@@ -170,12 +170,12 @@ describe( 'FontCommand', () => {
 
 			// It should not save that bold was executed at position ( root, [ 0, 1 ] ).
 
-			model.change( () => {
+			model.change( writer => {
 				// Simulate clicking right arrow key by changing selection ranges.
-				doc.selection.setRanges( [ new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 0, 2 ] ) ) ] );
+				writer.setSelection( [ new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 0, 2 ] ) ) ] );
 
 				// Get back to previous selection.
-				doc.selection.setRanges( [ new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 1 ] ) ) ] );
+				writer.setSelection( [ new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 1 ] ) ) ] );
 			} );
 
 			expect( command.value ).to.be.undefined;
@@ -193,15 +193,15 @@ describe( 'FontCommand', () => {
 
 			// Attribute should be stored.
 			// Simulate clicking somewhere else in the editor.
-			model.change( () => {
-				doc.selection.setRanges( [ new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 0, 2 ] ) ) ] );
+			model.change( writer => {
+				writer.setSelection( [ new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 0, 2 ] ) ) ] );
 			} );
 
 			expect( command.value ).to.be.undefined;
 
 			// Go back to where attribute was stored.
-			model.change( () => {
-				doc.selection.setRanges( [ new Range( new Position( root, [ 1, 0 ] ), new Position( root, [ 1, 0 ] ) ) ] );
+			model.change( writer => {
+				writer.setSelection( [ new Range( new Position( root, [ 1, 0 ] ), new Position( root, [ 1, 0 ] ) ) ] );
 			} );
 
 			// Attribute should be restored.