Skip to content

Commit

Permalink
Reverted change in createContextTree()
Browse files Browse the repository at this point in the history
  • Loading branch information
niegowski committed Jul 21, 2020
1 parent 3db5048 commit d52a22d
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 21 deletions.
6 changes: 1 addition & 5 deletions packages/ckeditor5-engine/src/conversion/upcastdispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ViewConsumable from './viewconsumable';
import ModelRange from '../model/range';
import ModelPosition from '../model/position';
import RootElement from '../model/rootelement';
import { SchemaContext } from '../model/schema';

import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
Expand Down Expand Up @@ -495,13 +494,10 @@ function createContextTree( contextDefinition, writer ) {
attributes[ key ] = item.getAttribute( key );
}

let current;
const current = writer.createElement( item.name, attributes );

if ( position ) {
current = writer.createElement( item.name, attributes );
writer.append( current, position );
} else {
current = new RootElement( null, item.name );
}

position = ModelPosition._createAt( current, 0 );
Expand Down
6 changes: 1 addition & 5 deletions packages/ckeditor5-engine/src/model/rootelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,11 @@ export default class RootElement extends Element {
* Assuming that the object being checked is an element, you can also check its
* {@link module:engine/model/element~Element#name name}:
*
* rootElement.is( '$root' ); // -> true if this is a $root element
* rootElement.is( 'rootElement', '$root' ); // -> same as above
* text.is( '$root' ); -> false
*
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
*
* @param {String} type Type to check when `name` parameter is present.
* Otherwise, it acts like the `name` parameter.
* @param {String} type Type to check.
* @param {String} [name] Element name.
* @returns {Boolean}
*/
Expand All @@ -84,7 +81,6 @@ export default class RootElement extends Element {
return type === 'rootElement' || type === 'model:rootElement' ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'element' || type === 'model:element' ||
type === this.name || type === 'model:' + this.name ||
type === 'node' || type === 'model:node';
}

Expand Down
4 changes: 1 addition & 3 deletions packages/ckeditor5-engine/src/view/rooteditableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export default class RootEditableElement extends EditableElement {
*
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
*
* @param {String} type Type to check when `name` parameter is present.
* Otherwise, it acts like the `name` parameter.
* @param {String} type Type to check.
* @param {String} [name] Element name.
* @returns {Boolean}
*/
Expand All @@ -72,7 +71,6 @@ export default class RootEditableElement extends EditableElement {
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
type === 'editableElement' || type === 'view:editableElement' ||
type === 'containerElement' || type === 'view:containerElement' ||
type === this.name || type === 'view:' + this.name ||
type === 'element' || type === 'view:element' ||
type === 'node' || type === 'view:node';
} else {
Expand Down
6 changes: 4 additions & 2 deletions packages/ckeditor5-engine/tests/model/rootelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ describe( 'RootElement', () => {
expect( root.is( 'model:element', '$root' ) ).to.be.true;
expect( root.is( 'element' ) ).to.be.true;
expect( root.is( 'model:element' ) ).to.be.true;
expect( root.is( '$root' ) ).to.be.true;
expect( root.is( 'model:$root' ) ).to.be.true;
expect( root.is( 'rootElement', '$root' ) ).to.be.true;
expect( root.is( 'model:rootElement', '$root' ) ).to.be.true;
expect( root.is( 'rootElement' ) ).to.be.true;
Expand All @@ -57,6 +55,10 @@ describe( 'RootElement', () => {
expect( root.is( '$textProxy' ) ).to.be.false;
expect( root.is( 'documentFragment' ) ).to.be.false;
expect( root.is( 'view:element' ) ).to.be.false;
expect( root.is( '$root' ) ).to.be.false;
expect( root.is( 'model:$root' ) ).to.be.false;
expect( root.is( 'node', '$root' ) ).to.be.false;
expect( root.is( 'model:node', '$root' ) ).to.be.false;
} );
} );
} );
6 changes: 4 additions & 2 deletions packages/ckeditor5-engine/tests/view/rooteditableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ describe( 'RootEditableElement', () => {
expect( el.is( 'view:element' ) ).to.be.true;
expect( el.is( 'element', 'div' ) ).to.be.true;
expect( el.is( 'view:element', 'div' ) ).to.be.true;
expect( el.is( 'element', 'div' ) ).to.be.true;
expect( el.is( 'view:div' ) ).to.be.true;
} );

it( 'should return false for other accept values', () => {
Expand All @@ -87,6 +85,10 @@ describe( 'RootEditableElement', () => {
expect( el.is( 'emptyElement' ) ).to.be.false;
expect( el.is( 'documentFragment' ) ).to.be.false;
expect( el.is( 'model:rootElement' ) ).to.be.false;
expect( el.is( 'div' ) ).to.be.false;
expect( el.is( 'view:div' ) ).to.be.false;
expect( el.is( 'node', 'div' ) ).to.be.false;
expect( el.is( 'view:node', 'div' ) ).to.be.false;
} );
} );

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-heading/src/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function dataViewModelH1Insertion( evt, data, conversionApi ) {
const modelCursor = data.modelCursor;
const viewItem = data.viewItem;

if ( !modelCursor.isAtStart || !modelCursor.parent.is( '$root' ) ) {
if ( !modelCursor.isAtStart || !modelCursor.parent.is( 'element', '$root' ) ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getInsertHorizontalLineParent( selection, model ) {

const parent = insertAt.parent;

if ( parent.isEmpty && !parent.is( '$root' ) ) {
if ( parent.isEmpty && !parent.is( 'element', '$root' ) ) {
return parent.parent;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-image/src/image/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function getInsertImageParent( selection, model ) {

const parent = insertAt.parent;

if ( parent.isEmpty && !parent.is( '$root' ) ) {
if ( parent.isEmpty && !parent.is( 'element', '$root' ) ) {
return parent.parent;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-page-break/src/pagebreakcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function getInsertPageBreakParent( selection, model ) {

const parent = insertAt.parent;

if ( parent.isEmpty && !parent.is( '$root' ) ) {
if ( parent.isEmpty && !parent.is( 'element', '$root' ) ) {
return parent.parent;
}

Expand Down

0 comments on commit d52a22d

Please sign in to comment.