+ 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
+ {\r
+ var cell;\r
+ // Check whether there's a spanning row here, do not break it.\r
+ if ( cloneRow[ i ].rowSpan > 1 && nextRow && cloneRow[ i ] == nextRow[ i ] )\r
+ {\r
+ cell = cloneRow[ i ];\r
+ cell.rowSpan += 1;\r
+ }\r
+ else\r
+ {\r
+ cell = new CKEDITOR.dom.element( cloneRow[ i ] ).clone();\r
+ cell.removeAttribute( 'rowSpan' );\r
+ !CKEDITOR.env.ie && cell.appendBogus();\r
+ newRow.append( cell );\r
+ cell = cell.$;\r
+ }\r