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

Commit

Permalink
Remove Position, Range, Selection imports from engine/model.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Oct 5, 2018
1 parent de08953 commit fe3c5fd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 45 deletions.
10 changes: 5 additions & 5 deletions src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';

import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';
Expand Down Expand Up @@ -372,7 +371,7 @@ export function viewModelConverter( evt, data, conversionApi ) {
writer.insert( listItem, splitResult.position );

// Remember position after list item, next list items will be inserted at this position.
let nextPosition = ModelPosition.createAfter( listItem );
let nextPosition = writer.createPositionAfter( listItem );

// Check all children of the converted `<li>`.
// At this point we assume there are no "whitespace" view text nodes in view list, between view list items.
Expand All @@ -384,19 +383,19 @@ export function viewModelConverter( evt, data, conversionApi ) {
}
// If it was not a list it was a "regular" list item content. Just convert it to `listItem`.
else {
conversionApi.convertItem( child, ModelPosition.createAt( listItem, 'end' ) );
conversionApi.convertItem( child, writer.createPositionAt( listItem, 'end' ) );
}
}

conversionStore.indent--;

// Result range starts before the first item and ends after the last.
data.modelRange = new ModelRange( data.modelCursor, nextPosition );
data.modelRange = writer.createRange( data.modelCursor, nextPosition );

// When modelCursor parent had to be split to insert list item.
if ( splitResult.cursorParent ) {
// Then continue conversion in split element.
data.modelCursor = ModelPosition.createAt( splitResult.cursorParent, 0 );
data.modelCursor = writer.createPositionAt( splitResult.cursorParent, 0 );
} else {
// Otherwise continue conversion after last list item.
data.modelCursor = data.modelRange.end;
Expand Down Expand Up @@ -824,6 +823,7 @@ function getSiblingListItem( modelItemOrPosition, options ) {
const sameIndent = !!options.sameIndent;
const smallerIndent = !!options.smallerIndent;

// TODO... ModelElement
const indent = modelItemOrPosition instanceof ModelElement ? modelItemOrPosition.getAttribute( 'listIndent' ) : options.listIndent;
let item = modelItemOrPosition instanceof ModelElement ? modelItemOrPosition.previousSibling : modelItemOrPosition.nodeBefore;

Expand Down
14 changes: 6 additions & 8 deletions tests/indentcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
import Model from '@ckeditor/ckeditor5-engine/src/model/model';
import IndentCommand from '../src/indentcommand';
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

describe( 'IndentCommand', () => {
Expand Down Expand Up @@ -177,9 +175,9 @@ describe( 'IndentCommand', () => {

it( 'should increment indent of all selected item when multiple items are selected', () => {
model.change( writer => {
writer.setSelection( new Range(
new Position( root.getChild( 1 ), [ 0 ] ),
new Position( root.getChild( 3 ), [ 1 ] )
writer.setSelection( writer.createRange(
writer.createPositionFromPath( root.getChild( 1 ), [ 0 ] ),
writer.createPositionFromPath( root.getChild( 3 ), [ 1 ] )
) );
} );

Expand Down Expand Up @@ -294,9 +292,9 @@ describe( 'IndentCommand', () => {

it( 'should outdent all selected item when multiple items are selected', () => {
model.change( writer => {
writer.setSelection( new Range(
new Position( root.getChild( 1 ), [ 0 ] ),
new Position( root.getChild( 3 ), [ 1 ] )
writer.setSelection( writer.createRange(
writer.createPositionFromPath( root.getChild( 1 ), [ 0 ] ),
writer.createPositionFromPath( root.getChild( 3 ), [ 1 ] )
) );
} );

Expand Down
26 changes: 12 additions & 14 deletions tests/listcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
import Model from '@ckeditor/ckeditor5-engine/src/model/model';
import ListCommand from '../src/listcommand';
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

describe( 'ListCommand', () => {
Expand Down Expand Up @@ -306,9 +304,9 @@ describe( 'ListCommand', () => {
// From first paragraph to second paragraph.
// Command value=false, we are turning on list items.
model.change( writer => {
writer.setSelection( new Range(
Position.createAt( root.getChild( 2 ), 0 ),
Position.createAt( root.getChild( 3 ), 'end' )
writer.setSelection( writer.createRange(
writer.createPositionAt( root.getChild( 2 ), 0 ),
writer.createPositionAt( root.getChild( 3 ), 'end' )
) );
} );

Expand All @@ -331,9 +329,9 @@ describe( 'ListCommand', () => {
// From second bullet list item to first numbered list item.
// Command value=true, we are turning off list items.
model.change( writer => {
writer.setSelection( new Range(
Position.createAt( root.getChild( 1 ), 0 ),
Position.createAt( root.getChild( 4 ), 'end' )
writer.setSelection( writer.createRange(
writer.createPositionAt( root.getChild( 1 ), 0 ),
writer.createPositionAt( root.getChild( 4 ), 'end' )
) );
} );

Expand All @@ -356,9 +354,9 @@ describe( 'ListCommand', () => {
it( 'should change closest listItem\'s type', () => {
// From first numbered lsit item to third bulleted list item.
model.change( writer => {
writer.setSelection( new Range(
Position.createAt( root.getChild( 4 ), 0 ),
Position.createAt( root.getChild( 6 ), 0 )
writer.setSelection( writer.createRange(
writer.createPositionAt( root.getChild( 4 ), 0 ),
writer.createPositionAt( root.getChild( 6 ), 0 )
) );
} );

Expand All @@ -381,9 +379,9 @@ describe( 'ListCommand', () => {
it( 'should handle outdenting sub-items when list item is turned off', () => {
// From first numbered list item to third bulleted list item.
model.change( writer => {
writer.setSelection( new Range(
Position.createAt( root.getChild( 1 ), 0 ),
Position.createAt( root.getChild( 5 ), 'end' )
writer.setSelection( writer.createRange(
writer.createPositionAt( root.getChild( 1 ), 0 ),
writer.createPositionAt( root.getChild( 5 ), 'end' )
) );
} );

Expand Down
42 changes: 24 additions & 18 deletions tests/listediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import ListEditing from '../src/listediting';
import ListCommand from '../src/listcommand';

import ModelDocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment';
import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
import ModelText from '@ckeditor/ckeditor5-engine/src/model/text';
import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';
import ViewUIElement from '@ckeditor/ckeditor5-engine/src/view/uielement';

Expand Down Expand Up @@ -426,7 +422,7 @@ describe( 'ListEditing', () => {
describe( 'model to view', () => {
function test( testName, modelPath, viewPath ) {
it( testName, () => {
const modelPos = new ModelPosition( modelRoot, modelPath );
const modelPos = model.createPositionFromPath( modelRoot, modelPath );
const viewPos = mapper.toViewPosition( modelPos );

expect( viewPos.root ).to.equal( viewRoot );
Expand Down Expand Up @@ -1417,7 +1413,7 @@ describe( 'ListEditing', () => {
describe( 'model to view', () => {
function test( testName, modelPath, viewPath ) {
it( testName, () => {
const modelPos = new ModelPosition( modelRoot, modelPath );
const modelPos = model.createPositionFromPath( modelRoot, modelPath );
const viewPos = mapper.toViewPosition( modelPos );

expect( viewPos.root ).to.equal( viewRoot );
Expand Down Expand Up @@ -3112,7 +3108,7 @@ describe( 'ListEditing', () => {
model.change( writer => {
setModelData( model, input );

const targetPosition = ModelPosition.createAt( modelRoot, offset );
const targetPosition = writer.createPositionAt( modelRoot, offset );

writer.move( modelDoc.selection.getFirstRange(), targetPosition );
} );
Expand Down Expand Up @@ -3327,13 +3323,16 @@ describe( 'ListEditing', () => {
'<listItem listType="bulleted" listIndent="2">C</listItem>'
);

editor.model.insertContent(
model.insertContent(
parseModel(
'<listItem listType="bulleted" listIndent="0">X</listItem>' +
'<listItem listType="bulleted" listIndent="1">Y</listItem>',
model.schema
),
new ModelRange( new ModelPosition( modelRoot, [ 1, 1 ] ), new ModelPosition( modelRoot, [ 1, 1 ] ) )
model.createRange(
model.createPositionFromPath( modelRoot, [ 1, 1 ] ),
model.createPositionFromPath( modelRoot, [ 1, 1 ] )
)
);

expect( getModelData( model ) ).to.equal(
Expand All @@ -3352,7 +3351,12 @@ describe( 'ListEditing', () => {
'<listItem listType="bulleted" listIndent="2">C</listItem>'
);

editor.model.insertContent( new ModelElement( 'listItem', { listType: 'bulleted', listIndent: '0' }, 'X' ) );
model.change( writer => {
const listItem = writer.createElement( 'listItem', { listType: 'bulleted', listIndent: '0' } );
writer.insertText( 'X', listItem );

model.insertContent( listItem );
} );

expect( getModelData( model ) ).to.equal(
'<listItem listIndent="0" listType="bulleted">A</listItem>' +
Expand All @@ -3369,7 +3373,9 @@ describe( 'ListEditing', () => {
'<listItem listType="bulleted" listIndent="2">C</listItem>'
);

editor.model.insertContent( new ModelText( 'X' ) );
model.change( writer => {
model.insertContent( writer.createText( 'X' ) );
} );

expect( getModelData( model ) ).to.equal(
'<listItem listIndent="0" listType="bulleted">A</listItem>' +
Expand Down Expand Up @@ -3955,9 +3961,9 @@ describe( 'ListEditing', () => {

function testMove( testName, input, rootOffset, output, testUndo = true ) {
const actionCallback = selection => {
const targetPosition = ModelPosition.createAt( modelRoot, rootOffset );

model.change( writer => {
const targetPosition = writer.createPositionAt( modelRoot, rootOffset );

writer.move( selection.getFirstRange(), targetPosition );
} );
};
Expand Down Expand Up @@ -4011,7 +4017,7 @@ describe( 'ListEditing', () => {
// Ensure no undo step is generated.
model.enqueueChange( 'transparent', writer => {
// Replace existing model in document by new one.
writer.remove( ModelRange.createIn( modelRoot ) );
writer.remove( writer.createRangeIn( modelRoot ) );
writer.insert( modelDocumentFragment, modelRoot );

// Clean up previous document selection.
Expand All @@ -4022,13 +4028,13 @@ describe( 'ListEditing', () => {
const ranges = [];

for ( const range of selection.getRanges() ) {
const start = new ModelPosition( modelRoot, range.start.path );
const end = new ModelPosition( modelRoot, range.end.path );
const start = model.createPositionFromPath( modelRoot, range.start.path );
const end = model.createPositionFromPath( modelRoot, range.end.path );

ranges.push( new ModelRange( start, end ) );
ranges.push( model.createRange( start, end ) );
}

return new Selection( ranges );
return model.createSelection( ranges );
}
}
} );

0 comments on commit fe3c5fd

Please sign in to comment.