瀏覽代碼

Aligned code to the changes in DocumentSelection API.

Maciej Gołaszewski 7 年之前
父節點
當前提交
f9e6781c0f

+ 3 - 3
packages/ckeditor5-highlight/src/highlightcommand.js

@@ -74,16 +74,16 @@ export default class HighlightCommand extends Command {
 					if ( !highlighter || this.value === highlighter ) {
 						// ...remove attribute when passing highlighter different then current or executing "eraser".
 						writer.removeAttribute( 'highlight', highlightRange );
-						selection.removeAttribute( 'highlight' );
+						writer.removeSelectionAttribute( 'highlight' );
 					} else {
 						// ...update `highlight` value.
 						writer.setAttribute( 'highlight', highlighter, highlightRange );
 
 						// And create new range wrapping changed highlighter.
-						selection.setRanges( [ highlightRange ] );
+						writer.setSelection( [ highlightRange ] );
 					}
 				} else if ( highlighter ) {
-					selection.setAttribute( 'highlight', highlighter );
+					writer.setSelectionAttribute( 'highlight', highlighter );
 				}
 			} else {
 				for ( const range of ranges ) {

+ 7 - 7
packages/ckeditor5-highlight/tests/highlightcommand.js

@@ -130,12 +130,12 @@ describe( 'HighlightCommand', () => {
 
 					// 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;
@@ -153,15 +153,15 @@ describe( 'HighlightCommand', () => {
 
 					// 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.