From 32019b7d732391de2aef188dd9295f5b4e38e14b Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 25 Jan 2018 16:50:52 +0100 Subject: [PATCH] Aligned code to the changes in DocumentSelection API. --- src/attributecommand.js | 4 ++-- tests/attributecommand.js | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/attributecommand.js b/src/attributecommand.js index 6dde80b..c569f36 100644 --- a/src/attributecommand.js +++ b/src/attributecommand.js @@ -91,9 +91,9 @@ export default class AttributeCommand extends Command { model.change( writer => { if ( selection.isCollapsed ) { if ( value ) { - selection.setAttribute( this.attributeKey, true ); + writer.setSelectionAttribute( this.attributeKey, true ); } else { - selection.removeAttribute( this.attributeKey ); + writer.removeSelectionAttribute( this.attributeKey ); } } else { const ranges = model.schema.getValidRanges( selection.getRanges(), this.attributeKey ); diff --git a/tests/attributecommand.js b/tests/attributecommand.js index eae332e..86da652 100644 --- a/tests/attributecommand.js +++ b/tests/attributecommand.js @@ -50,20 +50,20 @@ describe( 'AttributeCommand', () => { describe( 'value', () => { it( 'is true when selection has the attribute', () => { - model.change( () => { - doc.selection.setAttribute( attrKey, true ); + model.change( writer => { + writer.setSelectionAttribute( attrKey, true ); } ); expect( command.value ).to.be.true; } ); it( 'is false when selection does not have the attribute', () => { - model.change( () => { - doc.selection.setAttribute( attrKey, true ); + model.change( writer => { + writer.setSelectionAttribute( attrKey, true ); } ); - model.change( () => { - doc.selection.removeAttribute( attrKey ); + model.change( writer => { + writer.removeSelectionAttribute( attrKey ); } ); expect( command.value ).to.be.false; @@ -202,12 +202,12 @@ describe( 'AttributeCommand', () => { // 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.false; @@ -225,15 +225,15 @@ describe( 'AttributeCommand', () => { // 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.false; // 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.