Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Aligned code to changes in DocumentSelection API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Jan 25, 2018
1 parent aa46ffb commit f2865e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 10 additions & 5 deletions tests/headingcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} );

Expand All @@ -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;
Expand All @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand All @@ -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' );

Expand Down

0 comments on commit f2865e4

Please sign in to comment.