JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / tabletools / plugin.js
index d68954a..6266912 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -86,158 +86,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                return retval;\r
        }\r
 \r
-       function createTableMap( $refCell )\r
-       {\r
-               var refCell = new CKEDITOR.dom.element( $refCell );\r
-               var $table = ( refCell.getName() == 'table' ? $refCell : refCell.getAscendant( 'table' ) ).$;\r
-               var $rows = $table.rows;\r
-\r
-               // Row and column counters.\r
-               var r = -1;\r
-               var map = [];\r
-               for ( var i = 0 ; i < $rows.length ; i++ )\r
-               {\r
-                       r++;\r
-                       if ( !map[ r ] )\r
-                               map[ r ] = [];\r
-\r
-                       var c = -1;\r
-\r
-                       for ( var j = 0 ; j < $rows[ i ].cells.length ; j++ )\r
-                       {\r
-                               var $cell = $rows[ i ].cells[ j ];\r
-\r
-                               c++;\r
-                               while ( map[ r ][ c ] )\r
-                                       c++;\r
-\r
-                               var colSpan = isNaN( $cell.colSpan ) ? 1 : $cell.colSpan;\r
-                               var rowSpan = isNaN( $cell.rowSpan ) ? 1 : $cell.rowSpan;\r
-\r
-                               for ( var rs = 0 ; rs < rowSpan ; rs++ )\r
-                               {\r
-                                       if ( !map[ r + rs ] )\r
-                                               map[ r + rs ] = [];\r
-\r
-                                       for ( var cs = 0 ; cs < colSpan ; cs++ )\r
-                                               map [ r + rs ][ c + cs ] = $rows[ i ].cells[ j ];\r
-                               }\r
-\r
-                               c += colSpan - 1;\r
-                       }\r
-               }\r
-\r
-               return map;\r
-       }\r
-\r
-       function installTableMap( tableMap, $table )\r
-       {\r
-               /*\r
-                * IE BUG: rowSpan is always 1 in IE if the cell isn't attached to a row. So\r
-                * store is separately in another attribute. (#1917)\r
-                */\r
-               var rowSpanAttr = CKEDITOR.env.ie ? '_cke_rowspan' : 'rowSpan';\r
-\r
-               /*\r
-                * Disconnect all the cells in tableMap from their parents, set all colSpan\r
-                * and rowSpan attributes to 1.\r
-                */\r
-               for ( var i = 0 ; i < tableMap.length ; i++ )\r
-               {\r
-                       for ( var j = 0 ; j < tableMap[ i ].length ; j++ )\r
-                       {\r
-                               var $cell = tableMap[ i ][ j ];\r
-                               if ( $cell.parentNode )\r
-                                       $cell.parentNode.removeChild( $cell );\r
-                               $cell.colSpan = $cell[ rowSpanAttr ] = 1;\r
-                       }\r
-               }\r
-\r
-               // Scan by rows and set colSpan.\r
-               var maxCol = 0;\r
-               for ( i = 0 ; i < tableMap.length ; i++ )\r
-               {\r
-                       for ( j = 0 ; j < tableMap[ i ].length ; j++ )\r
-                       {\r
-                               $cell = tableMap[ i ][ j ];\r
-                               if ( !$cell )\r
-                                       continue;\r
-                               if ( j > maxCol )\r
-                                       maxCol = j;\r
-                               if ( $cell[ '_cke_colScanned' ] )\r
-                                       continue;\r
-                               if ( tableMap[ i ][ j - 1 ] == $cell )\r
-                                       $cell.colSpan++;\r
-                               if ( tableMap[ i ][ j + 1 ] != $cell )\r
-                                       $cell[ '_cke_colScanned' ] = 1;\r
-                       }\r
-               }\r
-\r
-               // Scan by columns and set rowSpan.\r
-               for ( i = 0 ; i <= maxCol ; i++ )\r
-               {\r
-                       for ( j = 0 ; j < tableMap.length ; j++ )\r
-                       {\r
-                               if ( !tableMap[ j ] )\r
-                                       continue;\r
-                               $cell = tableMap[ j ][ i ];\r
-                               if ( !$cell || $cell[ '_cke_rowScanned' ] )\r
-                                       continue;\r
-                               if ( tableMap[ j - 1 ] && tableMap[ j - 1 ][ i ] == $cell )\r
-                                       $cell[ rowSpanAttr ]++;\r
-                               if ( !tableMap[ j + 1 ] || tableMap[ j + 1 ][ i ] != $cell  )\r
-                                       $cell[ '_cke_rowScanned' ] = 1;\r
-                       }\r
-               }\r
-\r
-               // Clear all temporary flags.\r
-               for ( i = 0 ; i < tableMap.length ; i++ )\r
-               {\r
-                       for ( j = 0 ; j < tableMap[ i ].length ; j++ )\r
-                       {\r
-                               $cell = tableMap[ i ][ j ];\r
-                               removeRawAttribute( $cell, '_cke_colScanned' );\r
-                               removeRawAttribute( $cell, '_cke_rowScanned' );\r
-                       }\r
-               }\r
-\r
-               // Insert physical rows and columns to table.\r
-               for ( i = 0 ; i < tableMap.length ; i++ )\r
-               {\r
-                       var $row = $table.ownerDocument.createElement( 'tr' );\r
-                       for ( j = 0 ; j < tableMap[ i ].length ; )\r
-                       {\r
-                               $cell = tableMap[ i ][ j ];\r
-                               if ( tableMap[ i - 1 ] && tableMap[ i - 1 ][ j ] == $cell )\r
-                               {\r
-                                       j += $cell.colSpan;\r
-                                       continue;\r
-                               }\r
-                               $row.appendChild( $cell );\r
-                               if ( rowSpanAttr != 'rowSpan' )\r
-                               {\r
-                                       $cell.rowSpan = $cell[ rowSpanAttr ];\r
-                                       $cell.removeAttribute( rowSpanAttr );\r
-                               }\r
-                               j += $cell.colSpan;\r
-                               if ( $cell.colSpan == 1 )\r
-                                       $cell.removeAttribute( 'colSpan' );\r
-                               if ( $cell.rowSpan == 1 )\r
-                                       $cell.removeAttribute( 'rowSpan' );\r
-                       }\r
-\r
-                       if ( CKEDITOR.env.ie )\r
-                               $table.rows[ i ].replaceNode( $row );\r
-                       else\r
-                       {\r
-                               var dest = new CKEDITOR.dom.element( $table.rows[ i ] );\r
-                               var src = new CKEDITOR.dom.element( $row );\r
-                               dest.setHtml( '' );\r
-                               src.moveChildren( dest );\r
-                       }\r
-               }\r
-       }\r
-\r
        function clearRow( $tr )\r
        {\r
                // Get the array of row's cells.\r
@@ -416,6 +264,368 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                }\r
        }\r
 \r
+       // Remove filler at end and empty spaces around the cell content.\r
+       function trimCell( cell )\r
+       {\r
+               var bogus = cell.getBogus();\r
+               bogus && bogus.remove();\r
+               cell.trim();\r
+       }\r
+\r
+       function placeCursorInCell( cell, placeAtEnd )\r
+       {\r
+               var range = new CKEDITOR.dom.range( cell.getDocument() );\r
+               if ( !range[ 'moveToElementEdit' + ( placeAtEnd ? 'End' : 'Start' ) ]( cell ) )\r
+               {\r
+                       range.selectNodeContents( cell );\r
+                       range.collapse( placeAtEnd ? false : true );\r
+               }\r
+               range.select( true );\r
+       }\r
+\r
+       function buildTableMap( table )\r
+       {\r
+\r
+               var aRows = table.$.rows ;\r
+\r
+               // Row and Column counters.\r
+               var r = -1 ;\r
+\r
+               var aMap = [];\r
+\r
+               for ( var i = 0 ; i < aRows.length ; i++ )\r
+               {\r
+                       r++ ;\r
+                       !aMap[r] && ( aMap[r] = [] );\r
+\r
+                       var c = -1 ;\r
+\r
+                       for ( var j = 0 ; j < aRows[i].cells.length ; j++ )\r
+                       {\r
+                               var oCell = aRows[i].cells[j] ;\r
+\r
+                               c++ ;\r
+                               while ( aMap[r][c] )\r
+                                       c++ ;\r
+\r
+                               var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;\r
+                               var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;\r
+\r
+                               for ( var rs = 0 ; rs < iRowSpan ; rs++ )\r
+                               {\r
+                                       if ( !aMap[r + rs] )\r
+                                               aMap[r + rs] = new Array() ;\r
+\r
+                                       for ( var cs = 0 ; cs < iColSpan ; cs++ )\r
+                                       {\r
+                                               aMap[r + rs][c + cs] = aRows[i].cells[j] ;\r
+                                       }\r
+                               }\r
+\r
+                               c += iColSpan - 1 ;\r
+                       }\r
+               }\r
+               return aMap ;\r
+       }\r
+\r
+       function cellInRow( tableMap, rowIndex, cell )\r
+       {\r
+               var oRow = tableMap[ rowIndex ];\r
+               if( typeof cell == 'undefined' )\r
+                       return oRow;\r
+\r
+               for ( var c = 0 ; oRow && c < oRow.length ; c++ )\r
+               {\r
+                       if ( cell.is && oRow[c] == cell.$ )\r
+                               return c;\r
+                       else if( c == cell )\r
+                               return new CKEDITOR.dom.element( oRow[ c ] );\r
+               }\r
+               return cell.is ? -1 : null;\r
+       }\r
+\r
+       function cellInCol( tableMap, colIndex, cell )\r
+       {\r
+               var oCol = [];\r
+               for ( var r = 0; r < tableMap.length; r++ )\r
+               {\r
+                       var row = tableMap[ r ];\r
+                       if( typeof cell == 'undefined' )\r
+                               oCol.push( row[ colIndex ] );\r
+                       else if( cell.is && row[ colIndex ] == cell.$ )\r
+                               return r;\r
+                       else if( r == cell )\r
+                               return new CKEDITOR.dom.element( row[ colIndex ] );\r
+               }\r
+\r
+               return ( typeof cell == 'undefined' )? oCol : cell.is ? -1 :  null;\r
+       }\r
+\r
+       function mergeCells( selection, mergeDirection, isDetect )\r
+       {\r
+               var cells = getSelectedCells( selection );\r
+\r
+               // Invalid merge request if:\r
+               // 1. In batch mode despite that less than two selected.\r
+               // 2. In solo mode while not exactly only one selected.\r
+               // 3. Cells distributed in different table groups (e.g. from both thead and tbody).\r
+               var commonAncestor;\r
+               if ( ( mergeDirection ? cells.length != 1 : cells.length < 2 )\r
+                               || ( commonAncestor = selection.getCommonAncestor() )\r
+                               && commonAncestor.type == CKEDITOR.NODE_ELEMENT\r
+                               && commonAncestor.is( 'table' ) )\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               var     cell,\r
+                       firstCell = cells[ 0 ],\r
+                       table = firstCell.getAscendant( 'table' ),\r
+                       map = buildTableMap( table ),\r
+                       mapHeight = map.length,\r
+                       mapWidth = map[ 0 ].length,\r
+                       startRow = firstCell.getParent().$.rowIndex,\r
+                       startColumn = cellInRow( map, startRow, firstCell );\r
+\r
+               if( mergeDirection )\r
+               {\r
+                       var targetCell;\r
+                       try\r
+                       {\r
+                               targetCell =\r
+                                       map[ mergeDirection == 'up' ?\r
+                                                       ( startRow - 1 ):\r
+                                                       mergeDirection == 'down' ? ( startRow + 1 ) : startRow  ] [\r
+                                                mergeDirection == 'left' ?\r
+                                                       ( startColumn - 1 ):\r
+                                                mergeDirection == 'right' ?  ( startColumn + 1 ) : startColumn ];\r
+\r
+                       }\r
+                       catch( er )\r
+                       {\r
+                               return false;\r
+                       }\r
+\r
+                       // 1. No cell could be merged.\r
+                       // 2. Same cell actually.\r
+                       if( !targetCell || firstCell.$ == targetCell  )\r
+                               return false;\r
+\r
+                       // Sort in map order regardless of the DOM sequence.\r
+                       cells[ ( mergeDirection == 'up' || mergeDirection == 'left' ) ?\r
+                                'unshift' : 'push' ]( new CKEDITOR.dom.element( targetCell ) );\r
+               }\r
+\r
+               // Start from here are merging way ignorance (merge up/right, batch merge).\r
+               var     doc = firstCell.getDocument(),\r
+                       lastRowIndex = startRow,\r
+                       totalRowSpan = 0,\r
+                       totalColSpan = 0,\r
+                       // Use a documentFragment as buffer when appending cell contents.\r
+                       frag = !isDetect && new CKEDITOR.dom.documentFragment( doc ),\r
+                       dimension = 0;\r
+\r
+               for ( var i = 0; i < cells.length; i++ )\r
+               {\r
+                       cell = cells[ i ];\r
+\r
+                       var tr = cell.getParent(),\r
+                               cellFirstChild = cell.getFirst(),\r
+                               colSpan = cell.$.colSpan,\r
+                               rowSpan = cell.$.rowSpan,\r
+                               rowIndex = tr.$.rowIndex,\r
+                               colIndex = cellInRow( map, rowIndex, cell );\r
+\r
+                       // Accumulated the actual places taken by all selected cells.\r
+                       dimension += colSpan * rowSpan;\r
+                       // Accumulated the maximum virtual spans from column and row.\r
+                       totalColSpan = Math.max( totalColSpan, colIndex - startColumn + colSpan ) ;\r
+                       totalRowSpan = Math.max( totalRowSpan, rowIndex - startRow + rowSpan );\r
+\r
+                       if ( !isDetect )\r
+                       {\r
+                               // Trim all cell fillers and check to remove empty cells.\r
+                               if( trimCell( cell ), cell.getChildren().count() )\r
+                               {\r
+                                       // Merge vertically cells as two separated paragraphs.\r
+                                       if( rowIndex != lastRowIndex\r
+                                               && cellFirstChild\r
+                                               && !( cellFirstChild.isBlockBoundary\r
+                                                         && cellFirstChild.isBlockBoundary( { br : 1 } ) ) )\r
+                                       {\r
+                                               var last = frag.getLast( CKEDITOR.dom.walker.whitespaces( true ) );\r
+                                               if( last && !( last.is && last.is( 'br' ) ) )\r
+                                                       frag.append( new CKEDITOR.dom.element( 'br' ) );\r
+                                       }\r
+\r
+                                       cell.moveChildren( frag );\r
+                               }\r
+                               i ? cell.remove() : cell.setHtml( '' );\r
+                       }\r
+                       lastRowIndex = rowIndex;\r
+               }\r
+\r
+               if ( !isDetect )\r
+               {\r
+                       frag.moveChildren( firstCell );\r
+\r
+                       if( !CKEDITOR.env.ie )\r
+                               firstCell.appendBogus();\r
+\r
+                       if( totalColSpan >= mapWidth )\r
+                               firstCell.removeAttribute( 'rowSpan' );\r
+                       else\r
+                               firstCell.$.rowSpan = totalRowSpan;\r
+\r
+                       if( totalRowSpan >= mapHeight )\r
+                               firstCell.removeAttribute( 'colSpan' );\r
+                       else\r
+                               firstCell.$.colSpan = totalColSpan;\r
+\r
+                       // Swip empty <tr> left at the end of table due to the merging.\r
+                       var trs = new CKEDITOR.dom.nodeList( table.$.rows ),\r
+                               count = trs.count();\r
+\r
+                       for ( i = count - 1; i >= 0; i-- )\r
+                       {\r
+                               var tailTr = trs.getItem( i );\r
+                               if( !tailTr.$.cells.length )\r
+                               {\r
+                                       tailTr.remove();\r
+                                       count++;\r
+                                       continue;\r
+                               }\r
+                       }\r
+\r
+                       return firstCell;\r
+               }\r
+               // Be able to merge cells only if actual dimension of selected\r
+               // cells equals to the caculated rectangle.\r
+               else\r
+                       return ( totalRowSpan * totalColSpan ) == dimension;\r
+       }\r
+\r
+       function verticalSplitCell ( selection, isDetect )\r
+       {\r
+               var cells = getSelectedCells( selection );\r
+               if( cells.length > 1 )\r
+                       return false;\r
+               else if( isDetect )\r
+                       return true;\r
+\r
+               var cell = cells[ 0 ],\r
+                       tr = cell.getParent(),\r
+                       table = tr.getAscendant( 'table' ),\r
+                       map = buildTableMap( table ),\r
+                       rowIndex = tr.$.rowIndex,\r
+                       colIndex = cellInRow( map, rowIndex, cell ),\r
+                       rowSpan = cell.$.rowSpan,\r
+                       newCell,\r
+                       newRowSpan,\r
+                       newCellRowSpan,\r
+                       newRowIndex;\r
+\r
+               if( rowSpan > 1 )\r
+               {\r
+                       newRowSpan = Math.ceil( rowSpan / 2 );\r
+                       newCellRowSpan = Math.floor( rowSpan / 2 );\r
+                       newRowIndex = rowIndex + newRowSpan;\r
+                       var newCellTr = new CKEDITOR.dom.element( table.$.rows[ newRowIndex ] ),\r
+                               newCellRow = cellInRow( map, newRowIndex ),\r
+                               candidateCell;\r
+\r
+                       newCell = cell.clone();\r
+\r
+                       // Figure out where to insert the new cell by checking the vitual row.\r
+                       for ( var c = 0; c < newCellRow.length; c++ )\r
+                       {\r
+                               candidateCell = newCellRow[ c ];\r
+                               // Catch first cell actually following the column.\r
+                               if( candidateCell.parentNode == newCellTr.$\r
+                                       && c > colIndex )\r
+                               {\r
+                                       newCell.insertBefore( new CKEDITOR.dom.element( candidateCell ) );\r
+                                       break;\r
+                               }\r
+                               else\r
+                                       candidateCell = null;\r
+                       }\r
+\r
+                       // The destination row is empty, append at will.\r
+                       if( !candidateCell )\r
+                               newCellTr.append( newCell, true );\r
+               }\r
+               else\r
+               {\r
+                       newCellRowSpan = newRowSpan = 1;\r
+\r
+                       newCellTr = tr.clone();\r
+                       newCellTr.insertAfter( tr );\r
+                       newCellTr.append( newCell = cell.clone() );\r
+\r
+                       var cellsInSameRow = cellInRow( map, rowIndex );\r
+                       for ( var i = 0; i < cellsInSameRow.length; i++ )\r
+                               cellsInSameRow[ i ].rowSpan++;\r
+               }\r
+\r
+               if( !CKEDITOR.env.ie )\r
+                       newCell.appendBogus();\r
+\r
+               cell.$.rowSpan = newRowSpan;\r
+               newCell.$.rowSpan = newCellRowSpan;\r
+               if( newRowSpan == 1 )\r
+                       cell.removeAttribute( 'rowSpan' );\r
+               if( newCellRowSpan == 1 )\r
+                       newCell.removeAttribute( 'rowSpan' );\r
+\r
+               return newCell;\r
+       }\r
+\r
+       function horizontalSplitCell( selection, isDetect )\r
+       {\r
+               var cells = getSelectedCells( selection );\r
+               if( cells.length > 1 )\r
+                       return false;\r
+               else if( isDetect )\r
+                       return true;\r
+\r
+               var cell = cells[ 0 ],\r
+                       tr = cell.getParent(),\r
+                       table = tr.getAscendant( 'table' ),\r
+                       map = buildTableMap( table ),\r
+                       rowIndex = tr.$.rowIndex,\r
+                       colIndex = cellInRow( map, rowIndex, cell ),\r
+                       colSpan = cell.$.colSpan,\r
+                       newCell,\r
+                       newColSpan,\r
+                       newCellColSpan;\r
+\r
+               if( colSpan > 1 )\r
+               {\r
+                       newColSpan = Math.ceil( colSpan / 2 );\r
+                       newCellColSpan = Math.floor( colSpan / 2 );\r
+               }\r
+               else\r
+               {\r
+                       newCellColSpan = newColSpan = 1;\r
+                       var cellsInSameCol = cellInCol( map, colIndex );\r
+                       for ( var i = 0; i < cellsInSameCol.length; i++ )\r
+                               cellsInSameCol[ i ].colSpan++;\r
+               }\r
+               newCell = cell.clone();\r
+               newCell.insertAfter( cell );\r
+               if( !CKEDITOR.env.ie )\r
+                       newCell.appendBogus();\r
+\r
+               cell.$.colSpan = newColSpan;\r
+               newCell.$.colSpan = newCellColSpan;\r
+               if( newColSpan == 1 )\r
+                       cell.removeAttribute( 'colSpan' );\r
+               if( newCellColSpan == 1 )\r
+                       newCell.removeAttribute( 'colSpan' );\r
+\r
+               return newCell;\r
+       }\r
        // Context menu on table caption incorrect (#3834)\r
        var contextMenuTags = { thead : 1, tbody : 1, tfoot : 1, td : 1, tr : 1, th : 1 };\r
 \r
@@ -516,6 +726,46 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        }\r
                                } );\r
 \r
+                       editor.addCommand( 'cellMerge',\r
+                               {\r
+                                       exec : function( editor )\r
+                                       {\r
+                                               placeCursorInCell( mergeCells( editor.getSelection() ), true );\r
+                                       }\r
+                               } );\r
+\r
+                       editor.addCommand( 'cellMergeRight',\r
+                               {\r
+                                       exec : function( editor )\r
+                                       {\r
+                                               placeCursorInCell( mergeCells( editor.getSelection(), 'right' ), true );\r
+                                       }\r
+                               } );\r
+\r
+                       editor.addCommand( 'cellMergeDown',\r
+                               {\r
+                                       exec : function( editor )\r
+                                       {\r
+                                               placeCursorInCell( mergeCells( editor.getSelection(), 'down' ), true );\r
+                                       }\r
+                               } );\r
+\r
+                       editor.addCommand( 'cellVerticalSplit',\r
+                               {\r
+                                       exec : function( editor )\r
+                                       {\r
+                                               placeCursorInCell( verticalSplitCell( editor.getSelection() ) );\r
+                                       }\r
+                               } );\r
+\r
+                       editor.addCommand( 'cellHorizontalSplit',\r
+                               {\r
+                                       exec : function( editor )\r
+                                       {\r
+                                               placeCursorInCell( horizontalSplitCell( editor.getSelection() ) );\r
+                                       }\r
+                               } );\r
+\r
                        editor.addCommand( 'cellInsertBefore',\r
                                {\r
                                        exec : function( editor )\r
@@ -546,11 +796,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        order : 1,\r
                                                        getItems : function()\r
                                                        {\r
-                                                               var cells = getSelectedCells( editor.getSelection() );\r
+                                                               var selection = editor.getSelection(),\r
+                                                                       cells = getSelectedCells( selection );\r
                                                                return {\r
                                                                        tablecell_insertBefore : CKEDITOR.TRISTATE_OFF,\r
                                                                        tablecell_insertAfter : CKEDITOR.TRISTATE_OFF,\r
                                                                        tablecell_delete : CKEDITOR.TRISTATE_OFF,\r
+                                                                       tablecell_merge : mergeCells( selection, null, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                                       tablecell_merge_right : mergeCells( selection, 'right', true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                                       tablecell_merge_down : mergeCells( selection, 'down', true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                                       tablecell_split_vertical : verticalSplitCell( selection, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                                       tablecell_split_horizontal : horizontalSplitCell( selection, true ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
                                                                        tablecell_properties : cells.length > 0 ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED\r
                                                                };\r
                                                        }\r
@@ -580,12 +836,52 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        order : 15\r
                                                },\r
 \r
+                                               tablecell_merge :\r
+                                               {\r
+                                                       label : lang.cell.merge,\r
+                                                       group : 'tablecell',\r
+                                                       command : 'cellMerge',\r
+                                                       order : 16\r
+                                               },\r
+\r
+                                               tablecell_merge_right :\r
+                                               {\r
+                                                       label : lang.cell.mergeRight,\r
+                                                       group : 'tablecell',\r
+                                                       command : 'cellMergeRight',\r
+                                                       order : 17\r
+                                               },\r
+\r
+                                               tablecell_merge_down :\r
+                                               {\r
+                                                       label : lang.cell.mergeDown,\r
+                                                       group : 'tablecell',\r
+                                                       command : 'cellMergeDown',\r
+                                                       order : 18\r
+                                               },\r
+\r
+                                               tablecell_split_horizontal :\r
+                                               {\r
+                                                       label : lang.cell.splitHorizontal,\r
+                                                       group : 'tablecell',\r
+                                                       command : 'cellHorizontalSplit',\r
+                                                       order : 19\r
+                                               },\r
+\r
+                                               tablecell_split_vertical :\r
+                                               {\r
+                                                       label : lang.cell.splitVertical,\r
+                                                       group : 'tablecell',\r
+                                                       command : 'cellVerticalSplit',\r
+                                                       order : 20\r
+                                               },\r
+\r
                                                tablecell_properties :\r
                                                {\r
                                                        label : lang.cell.title,\r
                                                        group : 'tablecellproperties',\r
                                                        command : 'cellProperties',\r
-                                                       order : 20\r
+                                                       order : 21\r
                                                },\r
 \r
                                                tablerow :\r