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

Commit

Permalink
Fixed: List postfixers should check if attribute is allowed od elemen…
Browse files Browse the repository at this point in the history
…t before removing it.
  • Loading branch information
jodator committed May 14, 2018
1 parent 3c9e195 commit cd39904
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,15 @@ export function modelChangePostFixer( model, writer ) {
// In case of renamed element.
const item = entry.position.nodeAfter;

if ( item.hasAttribute( 'indent' ) ) {
// Only remove 'indent' attribute from items that doesn't allow such attribute. #103
if ( item.hasAttribute( 'indent' ) && !model.schema.checkAttribute( item, 'indent' ) ) {
writer.removeAttribute( 'indent', item );

applied = true;
}

if ( item.hasAttribute( 'type' ) ) {
// Only remove 'type' attribute from items that doesn't allow such attribute. #103
if ( item.hasAttribute( 'type' ) && !model.schema.checkAttribute( item, 'type' ) ) {
writer.removeAttribute( 'type', item );

applied = true;
Expand Down
23 changes: 23 additions & 0 deletions tests/listediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ describe( 'ListEditing', () => {
view = editor.editing.view;
viewDoc = view.document;
viewRoot = viewDoc.getRoot();

model.schema.register( 'foo', {
allowWhere: '$block',
allowAttributes: [ 'indent', 'type' ],
isBlock: true,
isObject: true
} );
} );
} );

Expand Down Expand Up @@ -3279,6 +3286,22 @@ describe( 'ListEditing', () => {

expect( getModelData( model, { withoutSelection: true } ) ).to.equal( expectedModel );
} );

it( 'should not remove attributes from elements that allows that attributes', () => {
const modelBefore =
'<listItem indent="0" type="bulleted">a</listItem>' +
'<listItem indent="1" type="bulleted">b</listItem>' +
'<foo indent="baz" type="bar"></foo>';

const expectedModel =
'<listItem indent="0" type="bulleted">a</listItem>' +
'<listItem indent="1" type="bulleted">b</listItem>' +
'<foo indent="baz" type="bar"></foo>';

setModelData( model, modelBefore );

expect( getModelData( model, { withoutSelection: true } ) ).to.equal( expectedModel );
} );
} );
} );

Expand Down

0 comments on commit cd39904

Please sign in to comment.