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 e76511f + 0d7330c commit 50b31e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
],
"dependencies": {
"@ckeditor/ckeditor5-core": "^11.0.1",
"@ckeditor/ckeditor5-engine": "^11.0.0",
"@ckeditor/ckeditor5-ui": "^11.1.0",
"@ckeditor/ckeditor5-utils": "^11.0.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-basic-styles": "^10.0.3",
"@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
17 changes: 8 additions & 9 deletions src/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import ParagraphCommand from './paragraphcommand';

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { SchemaContext } from '@ckeditor/ckeditor5-engine/src/model/schema';
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
import Range from '@ckeditor/ckeditor5-engine/src/model/range';

/**
* The paragraph feature for the editor.
Expand Down Expand Up @@ -49,6 +46,8 @@ export default class Paragraph extends Plugin {
// Handles elements not converted by plugins and checks if would be converted if
// we wraps them by a paragraph or changes them to a paragraph.
data.upcastDispatcher.on( 'element', ( evt, data, conversionApi ) => {
const writer = conversionApi.writer;

// When element is already consumed by higher priority converters then do nothing.
if ( !conversionApi.consumable.test( data.viewItem, { name: data.viewItem.name } ) ) {
return;
Expand All @@ -60,7 +59,7 @@ export default class Paragraph extends Plugin {
return;
}

const paragraph = conversionApi.writer.createElement( 'paragraph' );
const paragraph = writer.createElement( 'paragraph' );

// Find allowed parent for paragraph that we are going to insert.
// If current parent does not allow to insert paragraph but one of the ancestors does
Expand All @@ -73,15 +72,15 @@ export default class Paragraph extends Plugin {
}

// Insert paragraph in allowed position.
conversionApi.writer.insert( paragraph, splitResult.position );
writer.insert( paragraph, splitResult.position );

// Convert children to paragraph.
const { modelRange } = conversionApi.convertChildren( data.viewItem, Position.createAt( paragraph, 0 ) );
const { modelRange } = conversionApi.convertChildren( data.viewItem, writer.createPositionAt( paragraph, 0 ) );

// Output range starts before paragraph but ends inside it after last child.
// This is because we want to keep siblings inside the same paragraph as long as it is possible.
// When next node won't be allowed in a paragraph it will split this paragraph anyway.
data.modelRange = new Range( Position.createBefore( paragraph ), modelRange.end );
data.modelRange = writer.createRange( writer.createPositionBefore( paragraph ), modelRange.end );
data.modelCursor = data.modelRange.end;

// When element is not paragraph-like lets try to wrap it by a paragraph.
Expand Down Expand Up @@ -189,11 +188,11 @@ function wrapInParagraph( input, position, conversionApi ) {
const paragraph = conversionApi.writer.createElement( 'paragraph' );

conversionApi.writer.insert( paragraph, position );
return conversionApi.convertItem( input, Position.createAt( paragraph, 0 ) );
return conversionApi.convertItem( input, conversionApi.writer.createPositionAt( paragraph, 0 ) );
}

function isParagraphable( node, position, schema ) {
const context = new SchemaContext( position );
const context = schema.createContext( position );

// When paragraph is allowed in this context...
if ( !schema.checkChild( context, 'paragraph' ) ) {
Expand Down
7 changes: 3 additions & 4 deletions tests/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { upcastElementToElement, upcastElementToAttribute } from '@ckeditor/cked

import ModelDocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment';
import ModelText from '@ckeditor/ckeditor5-engine/src/model/text';
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';

describe( 'Paragraph feature', () => {
let model, editor, doc, root;
Expand Down Expand Up @@ -402,7 +401,7 @@ describe( 'Paragraph feature', () => {
expect( editor.getData() ).to.equal( '<p>Foobar</p>' );

model.change( writer => {
writer.remove( ModelRange.createIn( root ) );
writer.remove( writer.createRangeIn( root ) );
} );

expect( doc.getRoot().childCount ).to.equal( 1 );
Expand All @@ -417,7 +416,7 @@ describe( 'Paragraph feature', () => {
} );

model.change( writer => {
writer.remove( ModelRange.createIn( root ) );
writer.remove( writer.createRangeIn( root ) );
} );

expect( editor.getData() ).to.equal( '' );
Expand All @@ -428,7 +427,7 @@ describe( 'Paragraph feature', () => {

model.enqueueChange( writer => {
removeBatch = writer.batch;
writer.remove( ModelRange.createIn( root ) );
writer.remove( writer.createRangeIn( root ) );

model.enqueueChange( writer => {
attributeBatch = writer.batch;
Expand Down
12 changes: 7 additions & 5 deletions tests/paragraphcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
import ParagraphCommand from '../src/paragraphcommand';
import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
import Range from '@ckeditor/ckeditor5-engine/src/model/range';

import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

describe( 'ParagraphCommand', () => {
Expand Down Expand Up @@ -72,7 +71,7 @@ describe( 'ParagraphCommand', () => {
const element = document.getRoot().getChild( 1 );

model.change( writer => {
writer.setSelection( Range.createIn( element ) );
writer.setSelection( writer.createRangeIn( element ) );
} );

expect( command.value ).to.be.false;
Expand All @@ -83,7 +82,7 @@ describe( 'ParagraphCommand', () => {
const element = document.getRoot().getChild( 1 );

model.change( writer => {
writer.setSelection( Range.createIn( element ) );
writer.setSelection( writer.createRangeIn( element ) );

expect( command.value ).to.be.true;
command.refresh();
Expand Down Expand Up @@ -185,7 +184,10 @@ describe( 'ParagraphCommand', () => {

const secondToLastHeading = root.getChild( 1 );
const lastHeading = root.getChild( 2 );
const selection = new Selection( Range.createFromParentsAndOffsets( secondToLastHeading, 0, lastHeading, 1 ) );
const selection = model.createSelection( model.createRange(
model.createPositionAt( secondToLastHeading, 0 ),
model.createPositionAt( lastHeading, 1 )
) );

command.execute( { selection } );
expect( getData( model ) ).to.equal(
Expand Down

0 comments on commit 50b31e1

Please sign in to comment.