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

Commit

Permalink
Refactoring. Avoid using continue and locally defined functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Sep 13, 2019
1 parent 00338ae commit f6a31f8
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,30 +735,20 @@ export default class Schema {
for ( const node of nodes ) {
// When node is a `Text` it has no children, so just filter it out.
if ( node.is( 'text' ) ) {
removeDisallowedAttributeFromNode( this, node );

continue;
removeDisallowedAttributeFromNode( this, node, writer );
}

// In a case of `Element` iterates through positions between nodes inside this element
// and filter out node before the current position, or position parent when position
// is at start of an element. Using positions prevent from omitting merged nodes
// see https://github.com/ckeditor/ckeditor5-engine/issues/1789.
else {
const rangeInNode = Range._createIn( node );
const positionsInRange = rangeInNode.getPositions();

const rangeInNode = Range._createIn( node );
const positionsInRange = rangeInNode.getPositions();

for ( const position of positionsInRange ) {
const item = position.nodeBefore || position.parent;

removeDisallowedAttributeFromNode( this, item );
}
}
for ( const position of positionsInRange ) {
const item = position.nodeBefore || position.parent;

function removeDisallowedAttributeFromNode( schema, node ) {
for ( const attribute of node.getAttributeKeys() ) {
if ( !schema.checkAttribute( node, attribute ) ) {
writer.removeAttribute( attribute, node );
removeDisallowedAttributeFromNode( this, item, writer );
}
}
}
Expand Down Expand Up @@ -1611,3 +1601,11 @@ function* convertToMinimalFlatRanges( ranges ) {
yield* range.getMinimalFlatRanges();
}
}

function removeDisallowedAttributeFromNode( schema, node, writer ) {
for ( const attribute of node.getAttributeKeys() ) {
if ( !schema.checkAttribute( node, attribute ) ) {
writer.removeAttribute( attribute, node );
}
}
}

0 comments on commit f6a31f8

Please sign in to comment.