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 737755c + 51ebbfa commit 6490e07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
],
"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-editor-classic": "^11.0.1",
"@ckeditor/ckeditor5-engine": "^11.0.0",
"@ckeditor/ckeditor5-enter": "^10.1.2",
"@ckeditor/ckeditor5-essentials": "^10.1.2",
"@ckeditor/ckeditor5-heading": "^10.1.0",
"@ckeditor/ckeditor5-image": "^11.0.0",
"@ckeditor/ckeditor5-list": "^11.0.2",
"@ckeditor/ckeditor5-paragraph": "^10.0.3",
"@ckeditor/ckeditor5-typing": "^11.0.1",
"@ckeditor/ckeditor5-engine": "^10.2.0",
"@ckeditor/ckeditor5-basic-styles": "^10.0.3",
"eslint": "^5.5.0",
"eslint-config-ckeditor5": "^1.0.7",
"husky": "^0.14.3",
Expand Down
21 changes: 9 additions & 12 deletions src/blockquotecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

import Command from '@ckeditor/ckeditor5-core/src/command';

import Position from '@ckeditor/ckeditor5-engine/src/model/position';
import Element from '@ckeditor/ckeditor5-engine/src/model/element';
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
import first from '@ckeditor/ckeditor5-utils/src/first';

/**
Expand Down Expand Up @@ -113,7 +110,7 @@ export default class BlockQuoteCommand extends Command {
*/
_removeQuote( writer, blocks ) {
// Unquote all groups of block. Iterate in the reverse order to not break following ranges.
getRangesOfBlockGroups( blocks ).reverse().forEach( groupRange => {
getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => {
if ( groupRange.start.isAtStart && groupRange.end.isAtEnd ) {
writer.unwrap( groupRange.start.parent );

Expand All @@ -122,7 +119,7 @@ export default class BlockQuoteCommand extends Command {

// The group of blocks are at the beginning of an <bQ> so let's move them left (out of the <bQ>).
if ( groupRange.start.isAtStart ) {
const positionBefore = Position.createBefore( groupRange.start.parent );
const positionBefore = writer.createPositionBefore( groupRange.start.parent );

writer.move( groupRange, positionBefore );

Expand All @@ -137,7 +134,7 @@ export default class BlockQuoteCommand extends Command {

// Now we are sure that groupRange.end.isAtEnd is true, so let's move the blocks right.

const positionAfter = Position.createAfter( groupRange.end.parent );
const positionAfter = writer.createPositionAfter( groupRange.end.parent );

writer.move( groupRange, positionAfter );
} );
Expand All @@ -154,11 +151,11 @@ export default class BlockQuoteCommand extends Command {
const quotesToMerge = [];

// Quote all groups of block. Iterate in the reverse order to not break following ranges.
getRangesOfBlockGroups( blocks ).reverse().forEach( groupRange => {
getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => {
let quote = findQuote( groupRange.start );

if ( !quote ) {
quote = new Element( 'blockQuote' );
quote = writer.createElement( 'blockQuote' );

writer.wrap( groupRange, quote );
}
Expand All @@ -172,7 +169,7 @@ export default class BlockQuoteCommand extends Command {
// we want to keep the reference to the first (furthest left) one.
quotesToMerge.reverse().reduce( ( currentQuote, nextQuote ) => {
if ( currentQuote.nextSibling == nextQuote ) {
writer.merge( Position.createAfter( currentQuote ) );
writer.merge( writer.createPositionAfter( currentQuote ) );

return currentQuote;
}
Expand All @@ -194,7 +191,7 @@ function findQuote( elementOrPosition ) {
//
// @param {Array.<module:engine/model/element~Element>} blocks
// @returns {Array.<module:engine/model/range~Range>}
function getRangesOfBlockGroups( blocks ) {
function getRangesOfBlockGroups( writer, blocks ) {
let startPosition;
let i = 0;
const ranges = [];
Expand All @@ -204,11 +201,11 @@ function getRangesOfBlockGroups( blocks ) {
const nextBlock = blocks[ i + 1 ];

if ( !startPosition ) {
startPosition = Position.createBefore( block );
startPosition = writer.createPositionBefore( block );
}

if ( !nextBlock || block.nextSibling != nextBlock ) {
ranges.push( new Range( startPosition, Position.createAfter( block ) ) );
ranges.push( writer.createRange( startPosition, writer.createPositionAfter( block ) ) );
startPosition = null;
}

Expand Down
6 changes: 2 additions & 4 deletions src/blockquoteediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/

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

import BlockQuoteCommand from './blockquotecommand';

Expand Down Expand Up @@ -70,10 +68,10 @@ export default class BlockQuoteEditing extends Plugin {
return true;
} else if ( element.is( 'element' ) ) {
// Just added an element. Check its children to see if there are no nested blockQuotes somewhere inside.
const range = Range.createIn( element );
const range = writer.createRangeIn( element );

for ( const child of range.getItems() ) {
if ( child.is( 'blockQuote' ) && !schema.checkChild( Position.createBefore( child ), child ) ) {
if ( child.is( 'blockQuote' ) && !schema.checkChild( writer.createPositionBefore( child ), child ) ) {
writer.unwrap( child );

return true;
Expand Down
8 changes: 3 additions & 5 deletions tests/blockquoteediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';

import Range from '@ckeditor/ckeditor5-engine/src/model/range';

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

Expand Down Expand Up @@ -94,7 +92,7 @@ describe( 'BlockQuoteEditing', () => {
const root = model.document.getRoot();
const bq = root.getChild( 0 );

writer.remove( Range.createIn( bq ) );
writer.remove( writer.createRangeIn( bq ) );
} );

expect( editor.getData() ).to.equal( '<p>&nbsp;</p>' ); // Autoparagraphed.
Expand Down Expand Up @@ -122,7 +120,7 @@ describe( 'BlockQuoteEditing', () => {
model.change( writer => {
const root = model.document.getRoot();

writer.wrap( Range.createIn( root ), 'blockQuote' );
writer.wrap( writer.createRangeIn( root ), 'blockQuote' );
} );

expect( editor.getData() ).to.equal( '<blockquote><p>Foo</p><p>Bar</p></blockquote>' );
Expand All @@ -136,7 +134,7 @@ describe( 'BlockQuoteEditing', () => {
const root = model.document.getRoot();
const p = root.getChild( 0 ).getChild( 0 );

writer.setAttribute( 'bold', true, Range.createIn( p ) );
writer.setAttribute( 'bold', true, writer.createRangeIn( p ) );
} );

expect( editor.getData() ).to.equal( '<blockquote><p><strong>Foo</strong></p></blockquote>' );
Expand Down

0 comments on commit 6490e07

Please sign in to comment.