8
0
Prechádzať zdrojové kódy

Merge branch 'master' into i/6123

Maciej Gołaszewski 5 rokov pred
rodič
commit
f84c723ea6

+ 1 - 1
packages/ckeditor5-table/src/tableutils.js

@@ -228,7 +228,7 @@ export default class TableUtils extends Plugin {
 				const rowspan = parseInt( cell.getAttribute( 'rowspan' ) || 1 );
 				const colspan = parseInt( cell.getAttribute( 'colspan' ) || 1 );
 
-				if ( cell.index !== insertAt && colspan > 1 ) {
+				if ( cellIndex !== insertAt && colspan > 1 ) {
 					// If column is different than `insertAt`, it is a cell that spans over an inserted column (cell "a" & "i").
 					// For such cells expand them by a number of columns inserted.
 					writer.setAttribute( 'colspan', colspan + columnsToInsert, cell );

+ 42 - 0
packages/ckeditor5-table/tests/tableproperties/tablepropertiesediting-integration.js

@@ -10,7 +10,11 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
 import TableEditing from '../../src/tableediting';
 import TablePropertiesEditing from '../../src/tableproperties/tablepropertiesediting';
 
+import TableCellPropertiesEditing from '../../src/tablecellproperties/tablecellpropertiesediting';
+
 import AlignmentEditing from '@ckeditor/ckeditor5-alignment/src/alignmentediting';
+import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
+
 import { assertTableStyle } from '../_utils/utils';
 
 describe( 'table properties', () => {
@@ -39,6 +43,44 @@ describe( 'table properties', () => {
 			} );
 		} );
 
+		describe( 'Undo', () => {
+			let table;
+
+			beforeEach( async () => {
+				editor = await createEditorWithAdditionalPlugins( [ UndoEditing, TableCellPropertiesEditing ] );
+
+				model = editor.model;
+
+				table = createEmptyTable();
+			} );
+
+			// See https://github.com/ckeditor/ckeditor5/issues/6265.
+			it( 'should correctly undo setting table and then cell style', () => {
+				const firstCell = table.getChild( 0 ).getChild( 0 );
+
+				editor.model.change( writer => {
+					writer.setSelection( firstCell, 0 );
+				} );
+
+				editor.execute( 'tableBackgroundColor', { value: 'red' } );
+
+				editor.execute( 'tableCellBackgroundColor', { value: 'green' } );
+
+				expect( table.getAttribute( 'backgroundColor' ) ).to.equal( 'red' );
+				expect( firstCell.getAttribute( 'backgroundColor' ) ).to.equal( 'green' );
+
+				editor.execute( 'undo' );
+
+				expect( table.getAttribute( 'backgroundColor' ) ).to.equal( 'red' );
+				expect( firstCell.getAttribute( 'backgroundColor' ) ).to.be.undefined;
+
+				editor.execute( 'undo' );
+
+				expect( table.getAttribute( 'backgroundColor' ) ).to.be.undefined;
+				expect( firstCell.getAttribute( 'backgroundColor' ) ).to.be.undefined;
+			} );
+		} );
+
 		function createEmptyTable() {
 			setModelData(
 				model,

+ 18 - 0
packages/ckeditor5-table/tests/tableutils.js

@@ -272,6 +272,24 @@ describe( 'TableUtils', () => {
 			] ) );
 		} );
 
+		it( 'should properly insert column at beginning of row-col-spanned cell', () => {
+			setData( model, modelTable( [
+				[ '11', '12', '13' ],
+				[ '21', { colspan: 2, rowspan: 2, contents: '22[]' } ],
+				[ '31' ],
+				[ '41', '42', '43' ]
+			] ) );
+
+			tableUtils.insertColumns( root.getNodeByPath( [ 0 ] ), { at: 1, columns: 1 } );
+
+			assertEqualMarkup( getData( model ), modelTable( [
+				[ '11', '', '12', '13' ],
+				[ '21', '', { colspan: 2, rowspan: 2, contents: '22[]' } ],
+				[ '31', '' ],
+				[ '41', '', '42', '43' ]
+			] ) );
+		} );
+
 		it( 'should update table heading columns attribute when inserting column in headings section', () => {
 			setData( model, modelTable( [
 				[ '11[]', '12' ],