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

Commit

Permalink
Merge branch t/ckeditor5-engine/1555
Browse files Browse the repository at this point in the history
Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
  • Loading branch information
Reinmar committed Nov 1, 2018
2 parents 3d2ea98 + bc810c9 commit bfda8b2
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 269 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"ckeditor5-plugin"
],
"dependencies": {
"@ckeditor/ckeditor5-engine": "^11.0.0",
"@ckeditor/ckeditor5-paragraph": "^10.0.3",
"@ckeditor/ckeditor5-core": "^11.0.1",
"@ckeditor/ckeditor5-paragraph": "^10.0.3",
"@ckeditor/ckeditor5-ui": "^11.1.0",
"@ckeditor/ckeditor5-utils": "^11.0.0"
},
Expand All @@ -21,6 +20,7 @@
"@ckeditor/ckeditor5-block-quote": "^10.1.0",
"@ckeditor/ckeditor5-clipboard": "^10.0.3",
"@ckeditor/ckeditor5-editor-classic": "^11.0.1",
"@ckeditor/ckeditor5-engine": "^11.0.0",
"@ckeditor/ckeditor5-enter": "^10.1.2",
"@ckeditor/ckeditor5-heading": "^10.1.0",
"@ckeditor/ckeditor5-link": "^10.0.4",
Expand Down
384 changes: 193 additions & 191 deletions src/converters.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/listediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ export default class ListEditing extends Plugin {
editing.mapper.registerViewToModelLength( 'li', getViewListItemLength );
data.mapper.registerViewToModelLength( 'li', getViewListItemLength );

editing.mapper.on( 'modelToViewPosition', modelToViewPosition );
editing.mapper.on( 'viewToModelPosition', viewToModelPosition );
data.mapper.on( 'modelToViewPosition', modelToViewPosition );
editing.mapper.on( 'modelToViewPosition', modelToViewPosition( editing.view ) );
editing.mapper.on( 'viewToModelPosition', viewToModelPosition( editor.model ) );
data.mapper.on( 'modelToViewPosition', modelToViewPosition( editing.view ) );

editing.downcastDispatcher.on( 'insert', modelViewSplitOnInsert, { priority: 'high' } );
editing.downcastDispatcher.on( 'insert:listItem', modelViewInsertion );
editing.downcastDispatcher.on( 'insert:listItem', modelViewInsertion( editor.model ) );
data.downcastDispatcher.on( 'insert', modelViewSplitOnInsert, { priority: 'high' } );
data.downcastDispatcher.on( 'insert:listItem', modelViewInsertion );
data.downcastDispatcher.on( 'insert:listItem', modelViewInsertion( editor.model ) );

editing.downcastDispatcher.on( 'attribute:listType:listItem', modelViewChangeType );
data.downcastDispatcher.on( 'attribute:listType:listItem', modelViewChangeType );
editing.downcastDispatcher.on( 'attribute:listIndent:listItem', modelViewChangeIndent );
data.downcastDispatcher.on( 'attribute:listIndent:listItem', modelViewChangeIndent );
editing.downcastDispatcher.on( 'attribute:listIndent:listItem', modelViewChangeIndent( editor.model ) );
data.downcastDispatcher.on( 'attribute:listIndent:listItem', modelViewChangeIndent( editor.model ) );

editing.downcastDispatcher.on( 'remove:listItem', modelViewRemove );
editing.downcastDispatcher.on( 'remove:listItem', modelViewRemove( editor.model ) );
editing.downcastDispatcher.on( 'remove', modelViewMergeAfter, { priority: 'low' } );
data.downcastDispatcher.on( 'remove:listItem', modelViewRemove );
data.downcastDispatcher.on( 'remove:listItem', modelViewRemove( editor.model ) );
data.downcastDispatcher.on( 'remove', modelViewMergeAfter, { priority: 'low' } );

data.upcastDispatcher.on( 'element:ul', cleanList, { priority: 'high' } );
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
77 changes: 39 additions & 38 deletions tests/listediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,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';

import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
Expand Down Expand Up @@ -562,7 +555,7 @@ describe( 'ListEditing', () => {
describe( 'view to model', () => {
function test( testName, viewPath, modelPath ) {
it( testName, () => {
const viewPos = getViewPosition( viewRoot, viewPath );
const viewPos = getViewPosition( viewRoot, viewPath, view );
const modelPos = mapper.toModelPosition( viewPos );

expect( modelPos.root ).to.equal( modelRoot );
Expand All @@ -587,7 +580,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 @@ -1540,7 +1533,7 @@ describe( 'ListEditing', () => {
describe( 'view to model', () => {
function test( testName, viewPath, modelPath ) {
it( testName, () => {
const viewPos = getViewPosition( viewRoot, viewPath );
const viewPos = getViewPosition( viewRoot, viewPath, view );
const modelPos = mapper.toModelPosition( viewPos );

expect( modelPos.root ).to.equal( modelRoot );
Expand Down Expand Up @@ -1578,7 +1571,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 @@ -3273,7 +3266,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 @@ -3488,13 +3481,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 @@ -3513,7 +3509,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 @@ -3530,7 +3531,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 @@ -3672,7 +3675,9 @@ describe( 'ListEditing', () => {
setModelData( model, '<paragraph>[]</paragraph>' );

expect( () => {
editor.model.insertContent( new ModelDocumentFragment() );
model.change( writer => {
editor.model.insertContent( writer.createDocumentFragment() );
} );
} ).not.to.throw();
} );

Expand Down Expand Up @@ -3898,13 +3903,12 @@ describe( 'ListEditing', () => {
it( 'ul and ol should not be inserted before ui element - injectViewList()', () => {
editor.setData( '<ul><li>Foo</li><li>Bar</li></ul>' );

const uiElement = new ViewUIElement( 'span' );

// Append ui element at the end of first <li>.
view.change( writer => {
const firstChild = viewDoc.getRoot().getChild( 0 ).getChild( 0 );

writer.insert( ViewPosition.createAt( firstChild, 'end' ), uiElement );
const uiElement = writer.createUIElement( 'span' );
writer.insert( writer.createPositionAt( firstChild, 'end' ), uiElement );
} );

expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
Expand All @@ -3924,13 +3928,12 @@ describe( 'ListEditing', () => {
it( 'ul and ol should not be inserted before ui element - hoistNestedLists()', () => {
editor.setData( '<ul><li>Foo</li><li>Bar<ul><li>Xxx</li><li>Yyy</li></ul></li></ul>' );

const uiElement = new ViewUIElement( 'span' );

// Append ui element at the end of first <li>.
view.change( writer => {
const firstChild = viewDoc.getRoot().getChild( 0 ).getChild( 0 );

writer.insert( ViewPosition.createAt( firstChild, 'end' ), uiElement );
const uiElement = writer.createUIElement( 'span' );
writer.insert( writer.createPositionAt( firstChild, 'end' ), uiElement );
} );

expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
Expand All @@ -3947,20 +3950,18 @@ describe( 'ListEditing', () => {
} );

describe( 'remove converter should properly handle ui elements', () => {
let uiElement, liFoo, liBar;
let liFoo, liBar;

beforeEach( () => {
editor.setData( '<ul><li>Foo</li><li>Bar</li></ul>' );
liFoo = modelRoot.getChild( 0 );
liBar = modelRoot.getChild( 1 );

uiElement = new ViewUIElement( 'span' );
} );

it( 'ui element before <ul>', () => {
view.change( writer => {
// Append ui element before <ul>.
writer.insert( ViewPosition.createAt( viewRoot, 0 ), uiElement );
writer.insert( writer.createPositionAt( viewRoot, 0 ), writer.createUIElement( 'span' ) );
} );

model.change( writer => {
Expand All @@ -3974,7 +3975,7 @@ describe( 'ListEditing', () => {
it( 'ui element before first <li>', () => {
view.change( writer => {
// Append ui element before <ul>.
writer.insert( ViewPosition.createAt( viewRoot.getChild( 0 ), 0 ), uiElement );
writer.insert( writer.createPositionAt( viewRoot.getChild( 0 ), 0 ), writer.createUIElement( 'span' ) );
} );

model.change( writer => {
Expand All @@ -3988,7 +3989,7 @@ describe( 'ListEditing', () => {
it( 'ui element in the middle of list', () => {
view.change( writer => {
// Append ui element before <ul>.
writer.insert( ViewPosition.createAt( viewRoot.getChild( 0 ), 'end' ), uiElement );
writer.insert( writer.createPositionAt( viewRoot.getChild( 0 ), 'end' ), writer.createUIElement( 'span' ) );
} );

model.change( writer => {
Expand Down Expand Up @@ -4080,14 +4081,14 @@ describe( 'ListEditing', () => {
} );
} );

function getViewPosition( root, path ) {
function getViewPosition( root, path, view ) {
let parent = root;

while ( path.length > 1 ) {
parent = parent.getChild( path.shift() );
}

return new ViewPosition( parent, path[ 0 ] );
return view.createPositionAt( parent, path[ 0 ] );
}

function getViewPath( position ) {
Expand Down Expand Up @@ -4185,9 +4186,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 @@ -4241,7 +4242,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 @@ -4252,13 +4253,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 );
}
}
} );
Loading

0 comments on commit bfda8b2

Please sign in to comment.