Kaynağa Gözat

Updated createEmptyRows() to insert cells in forward order.

Kuba Niegowski 5 yıl önce
ebeveyn
işleme
399356e33a

+ 4 - 3
packages/ckeditor5-table/src/commands/utils.js

@@ -50,13 +50,14 @@ export function updateNumericAttribute( key, value, item, writer, defaultValue =
  * A common method to create an empty table cell. It creates a proper model structure as a table cell must have at least one block inside.
  *
  * @param {module:engine/model/writer~Writer} writer The model writer.
- * @param {module:engine/model/position~Position} insertPosition The position at which the table cell should be inserted.
+ * @param {module:engine/model/position~Position|module:engine/model/element~Element} insertPositionOrParentElement The position at which
+ * the table cell should be inserted. If the element is provided then it's end position is used.
  * @param {Object} attributes The element attributes.
  */
-export function createEmptyTableCell( writer, insertPosition, attributes = {} ) {
+export function createEmptyTableCell( writer, insertPositionOrParentElement, attributes = {} ) {
 	const tableCell = writer.createElement( 'tableCell', attributes );
 	writer.insertElement( 'paragraph', tableCell );
-	writer.insert( tableCell, insertPosition );
+	writer.insert( tableCell, insertPositionOrParentElement, 'end' );
 }
 
 /**

+ 6 - 5
packages/ckeditor5-table/src/tableutils.js

@@ -721,7 +721,7 @@ function createEmptyRows( writer, table, insertAt, rows, tableCellToInsert, attr
 
 		writer.insert( tableRow, table, insertAt );
 
-		createCells( tableCellToInsert, writer, writer.createPositionAt( tableRow, 'end' ), attributes );
+		createCells( tableCellToInsert, writer, tableRow, attributes );
 	}
 }
 
@@ -729,11 +729,12 @@ function createEmptyRows( writer, table, insertAt, rows, tableCellToInsert, attr
 //
 // @param {Number} columns The number of columns to create
 // @param {module:engine/model/writer~Writer} writer
-// @param {module:engine/model/position~Position} insertPosition
-function createCells( cells, writer, insertPosition, attributes = {} ) {
+// @param {module:engine/model/position~Position|module:engine/model/element~Element} insertPositionOrParentElement
+// @param {Object|Array.<Object>} attributes
+function createCells( cells, writer, insertPositionOrParentElement, attributes = {} ) {
 	for ( let i = 0; i < cells; i++ ) {
-		const cellAttributes = Array.isArray( attributes ) ? attributes[ attributes.length - i - 1 ] : attributes;
-		createEmptyTableCell( writer, insertPosition, cellAttributes );
+		const cellAttributes = Array.isArray( attributes ) ? attributes[ i ] : attributes;
+		createEmptyTableCell( writer, insertPositionOrParentElement, cellAttributes );
 	}
 }