diff --git a/packages/ckeditor5-html-support/src/datafilter.ts b/packages/ckeditor5-html-support/src/datafilter.ts index 13cb3ed3973..11a6c943d5f 100644 --- a/packages/ckeditor5-html-support/src/datafilter.ts +++ b/packages/ckeditor5-html-support/src/datafilter.ts @@ -461,7 +461,7 @@ export default class DataFilter extends Plugin { } // Remove the coupled GHS attributes on the same range as the feature attribute was removed. - for ( const { item } of change.range.getWalker( { shallow: true } ) ) { + for ( const { item } of change.range.getWalker() ) { for ( const attributeKey of attributeKeys ) { if ( item.hasAttribute( attributeKey ) ) { writer.removeAttribute( attributeKey, item ); diff --git a/packages/ckeditor5-html-support/tests/integrations/list.js b/packages/ckeditor5-html-support/tests/integrations/list.js index 84e260da737..75de9f6e450 100644 --- a/packages/ckeditor5-html-support/tests/integrations/list.js +++ b/packages/ckeditor5-html-support/tests/integrations/list.js @@ -8,6 +8,7 @@ import GeneralHtmlSupport from '../../src/generalhtmlsupport.js'; import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor.js'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph.js'; import ListEditing from '@ckeditor/ckeditor5-list/src/list/listediting.js'; +import TableEditing from '@ckeditor/ckeditor5-table/src/tableediting.js'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils.js'; import stubUid from '@ckeditor/ckeditor5-list/tests/list/_utils/uid.js'; @@ -28,7 +29,7 @@ describe( 'ListElementSupport', () => { editor = await ClassicTestEditor .create( editorElement, { - plugins: [ Paragraph, GeneralHtmlSupport, ListEditing ] + plugins: [ Paragraph, GeneralHtmlSupport, ListEditing, TableEditing ] } ); model = editor.model; dataFilter = editor.plugins.get( 'DataFilter' ); @@ -1013,6 +1014,145 @@ describe( 'ListElementSupport', () => { } ); } ); + describe( '#15527 and #15565', () => { + // See https://github.com/ckeditor/ckeditor5/issues/15527. + it( 'should not remove attribute from other elements (inside GHS div)', () => { + const dataFilter = editor.plugins.get( 'DataFilter' ); + + // Allow everything + dataFilter.allowElement( /^.*$/ ); + dataFilter.allowAttributes( { name: /^.*$/, attributes: true } ); + dataFilter.allowAttributes( { name: /^.*$/, classes: true } ); + + editor.setData( + '
' + + '
    ' + + '
  1. foo
  2. ' + + '
  3. ' + + '
    ' + + '
      ' + + '
    1. bar
    2. ' + + '
    ' + + '
    ' + + '
  4. ' + + '
' + + '
' + ); + + model.change( writer => { + writer.setSelection( model.document.getRoot().getNodeByPath( [ 0, 1, 0 ] ), 0 ); + } ); + + expect( getModelDataWithAttributes( model ) ).to.deep.equal( { + data: + '' + + '' + + 'foo' + + '' + + '' + + '' + + '[]bar' + + '' + + '' + + '', + attributes: { + 1: {}, + 2: {}, + 3: {}, + 4: {}, + 5: {}, + 6: {} + } + } ); + + editor.editing.view.document.fire( 'delete', { direction: 'backward', preventDefault() {} } ); + + expect( getModelDataWithAttributes( model, { withoutSelection: true } ) ).to.deep.equal( { + data: + '' + + '' + + 'foo' + + '' + + '' + + 'bar' + + '' + + '', + attributes: { + 1: {}, + 2: {}, + 3: {}, + 4: {} + } + } ); + } ); + + // See https://github.com/ckeditor/ckeditor5/issues/15565. + it( 'should not remove attribute from other elements (inside table cell)', () => { + const dataFilter = editor.plugins.get( 'DataFilter' ); + + // Allow everything + dataFilter.allowElement( /^.*$/ ); + dataFilter.allowAttributes( { name: /^.*$/, attributes: true } ); + dataFilter.allowAttributes( { name: /^.*$/, classes: true } ); + + editor.setData( + '' + ); + + model.change( writer => { + writer.setSelection( model.document.getRoot().getNodeByPath( [ 1, 0, 0, 0 ] ), 0 ); + } ); + + expect( getModelData( model ) ).to.equal( + '' + + ' ' + + '' + + '' + + '' + + '' + + '' + + '[]' + + '' + + '' + + '' + + '
' + ); + + editor.editing.view.document.fire( 'enter', { preventDefault() {} } ); + + expect( getModelData( model ) ).to.equal( + '' + + ' ' + + '' + + '' + + '' + + '' + + '' + + '[]' + + '' + + '' + + '' + + '
' + ); + } ); + } ); + function paragraph( text, id, indent, type, listAttributes ) { const attributeName = type === 'bulleted' ? 'htmlUlAttributes' :