- // Get the array of row's cells.\r
- var $cells = $tr.cells;\r
-\r
- // Empty all cells.\r
- for ( var i = 0 ; i < $cells.length ; i++ )\r
+ var cells = getSelectedCells( selection ),\r
+ firstCell = cells[ 0 ],\r
+ table = firstCell.getAscendant( 'table' ),\r
+ doc = firstCell.getDocument(),\r
+ startRow = cells[ 0 ].getParent(),\r
+ startRowIndex = startRow.$.rowIndex,\r
+ lastCell = cells[ cells.length - 1 ],\r
+ endRowIndex = lastCell.getParent().$.rowIndex + lastCell.$.rowSpan - 1,\r
+ endRow = new CKEDITOR.dom.element( table.$.rows[ endRowIndex ] ),\r
+ rowIndex = insertBefore ? startRowIndex : endRowIndex,\r
+ row = insertBefore ? startRow : endRow;\r
+\r
+ var map = CKEDITOR.tools.buildTableMap( table ),\r
+ cloneRow = map[ rowIndex ],\r
+ nextRow = insertBefore ? map[ rowIndex - 1 ] : map[ rowIndex + 1 ],\r
+ width = map[0].length;\r
+\r
+ var newRow = doc.createElement( 'tr' );\r
+ for ( var i = 0; i < width; i++ )\r