X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ftabletools%2Fplugin.js;h=1f1f4d197cc65f85c915d03134c1cbe91b00ae8c;hb=055b6b0792ce7dc53d47af606b367c04b927c2ab;hp=75900780f069e0ce5a0bfb4b04ba04064e597ae3;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/tabletools/plugin.js b/_source/plugins/tabletools/plugin.js index 7590078..1f1f4d1 100644 --- a/_source/plugins/tabletools/plugin.js +++ b/_source/plugins/tabletools/plugin.js @@ -86,7 +86,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return retval; } - function getFocusedCell( cellsToDelete ) { + function getFocusElementAfterDelCells( cellsToDelete ) { var i = 0, last = cellsToDelete.length - 1, database = {}, @@ -234,7 +234,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( $row.cells.length < ( cellIndex + 1 ) ) continue; - cell = new CKEDITOR.dom.element( $row.cells[ cellIndex ].cloneNode( false ) ); + cell = ( new CKEDITOR.dom.element( $row.cells[ cellIndex ] ) ).clone( false ); if ( !CKEDITOR.env.ie ) cell.appendBogus(); @@ -248,21 +248,65 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } + function getFocusElementAfterDelCols( cells ) + { + var cellIndexList = [], + table = cells[ 0 ] && cells[ 0 ].getAscendant( 'table' ), + i, length, + targetIndex, targetCell; + + // get the cellIndex list of delete cells + for ( i = 0, length = cells.length; i < length; i++ ) + cellIndexList.push( cells[i].$.cellIndex ); + + // get the focusable column index + cellIndexList.sort(); + for ( i = 1, length = cellIndexList.length; i < length; i++ ) + { + if ( cellIndexList[ i ] - cellIndexList[ i - 1 ] > 1 ) + { + targetIndex = cellIndexList[ i - 1 ] + 1; + break; + } + } + + if ( !targetIndex ) + targetIndex = cellIndexList[ 0 ] > 0 ? ( cellIndexList[ 0 ] - 1 ) + : ( cellIndexList[ cellIndexList.length - 1 ] + 1 ); + + // scan row by row to get the target cell + var rows = table.$.rows; + for ( i = 0, length = rows.length; i < length ; i++ ) + { + targetCell = rows[ i ].cells[ targetIndex ]; + if ( targetCell ) + break; + } + + return targetCell ? new CKEDITOR.dom.element( targetCell ) : table.getPrevious(); + } + function deleteColumns( selectionOrCell ) { if ( selectionOrCell instanceof CKEDITOR.dom.selection ) { - var colsToDelete = getSelectedCells( selectionOrCell ); - for ( var i = colsToDelete.length ; i >= 0 ; i-- ) + var colsToDelete = getSelectedCells( selectionOrCell ), + elementToFocus = getFocusElementAfterDelCols( colsToDelete ); + + for ( var i = colsToDelete.length - 1 ; i >= 0 ; i-- ) { if ( colsToDelete[ i ] ) deleteColumns( colsToDelete[ i ] ); } + + return elementToFocus; } else if ( selectionOrCell instanceof CKEDITOR.dom.element ) { // Get the cell's table. var table = selectionOrCell.getAscendant( 'table' ); + if ( !table ) + return null; // Get the cell index. var cellIndex = selectionOrCell.$.cellIndex; @@ -288,6 +332,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license row.$.removeChild( row.$.cells[ cellIndex ] ); } } + + return null; } function insertCell( selection, insertBefore ) @@ -315,7 +361,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var cellsToDelete = getSelectedCells( selectionOrCell ); var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' ); - var cellToFocus = getFocusedCell( cellsToDelete ); + var cellToFocus = getFocusElementAfterDelCells( cellsToDelete ); for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- ) deleteCells( cellsToDelete[ i ] ); @@ -726,9 +772,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license range.collapse(); selection.selectRanges( [ range ] ); - // If the table's parent has only one child, remove it as well. - if ( table.getParent().getChildCount() == 1 ) - table.getParent().remove(); + // If the table's parent has only one child, remove it,except body,as well.( #5416 ) + var parent = table.getParent(); + if ( parent.getChildCount() == 1 && parent.getName() != 'body' ) + parent.remove(); else table.remove(); } @@ -766,7 +813,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license exec : function( editor ) { var selection = editor.getSelection(); - deleteColumns( selection ); + var element = deleteColumns( selection ); + element && placeCursorInCell( element, true ); } } );