Ticket #5577: 5577_3.patch

File 5577_3.patch, 3.1 KB (added by brooks, 14 years ago)
  • _source/plugins/tabletools/plugin.js

     
    8686                return retval;
    8787        }
    8888
    89         function getFocusedCell( cellsToDelete ) {
     89        function getFocusElementAfterDelCells( cellsToDelete ) {
    9090                var i = 0,
    9191                        last = cellsToDelete.length - 1,
    9292                        database = {},
     
    247247                                cell.insertAfter( baseCell );
    248248                }
    249249        }
     250       
     251        function getFocusElementAfterDelCols( cells )
     252        {
     253                var cellIndexList = [],
     254                        table = cells[ 0 ] && cells[ 0 ].getAscendant( 'table' ),
     255                        i, length,
     256                        targetIndex, targetCell;
     257               
     258                // get the cellIndex list of delete cells
     259                for ( i = 0, length = cells.length; i < length; i++ )
     260                        cellIndexList.push( cells[i].$.cellIndex );
    250261
     262                // get the focusable column index
     263                cellIndexList.sort();
     264                for ( i = 1, length = cellIndexList.length; i < length; i++ )
     265                {
     266                        if ( cellIndexList[ i ] - cellIndexList[ i - 1 ] > 1 )
     267                        {
     268                                targetIndex = cellIndexList[ i - 1 ] + 1;
     269                                break;
     270                        }
     271                }
     272               
     273                if ( !targetIndex )
     274                        targetIndex = cellIndexList[ 0 ] > 0 ? ( cellIndexList[ 0 ] - 1 )
     275                                                        : ( cellIndexList[ cellIndexList.length - 1 ] + 1 );
     276
     277                // scan row by row to get the target cell
     278                var trs = table.$.getElementsByTagName( 'tr' );
     279                for ( i = 0, length = trs.length; i < length ; i++ )
     280                {
     281                        targetCell = trs[ i ].getElementsByTagName( 'td' )[ targetIndex ];
     282                        if ( targetCell )
     283                                break;
     284                }
     285
     286                return targetCell ?  new CKEDITOR.dom.element( targetCell ) :  table.getPrevious();
     287        }
     288
    251289        function deleteColumns( selectionOrCell )
    252290        {
    253291                if ( selectionOrCell instanceof CKEDITOR.dom.selection )
    254292                {
    255                         var colsToDelete = getSelectedCells( selectionOrCell );
    256                         for ( var i = colsToDelete.length ; i >= 0 ; i-- )
     293                        var colsToDelete = getSelectedCells( selectionOrCell ),
     294                                elementToFocus = getFocusElementAfterDelCols( colsToDelete );
     295
     296                        for ( var i = colsToDelete.length - 1 ; i >= 0 ; i-- )
    257297                        {
    258298                                if ( colsToDelete[ i ] )
    259299                                        deleteColumns( colsToDelete[ i ] );
    260300                        }
     301
     302                        return elementToFocus;
    261303                }
    262304                else if ( selectionOrCell instanceof CKEDITOR.dom.element )
    263305                {
    264306                        // Get the cell's table.
    265307                        var table = selectionOrCell.getAscendant( 'table' );
     308                        if ( !table )
     309                                return;
    266310
    267311                        // Get the cell index.
    268312                        var cellIndex = selectionOrCell.$.cellIndex;
     
    315359                {
    316360                        var cellsToDelete = getSelectedCells( selectionOrCell );
    317361                        var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' );
    318                         var cellToFocus   = getFocusedCell( cellsToDelete );
     362                        var cellToFocus   = getFocusElementAfterDelCells( cellsToDelete );
    319363
    320364                        for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- )
    321365                                deleteCells( cellsToDelete[ i ] );
     
    767811                                        exec : function( editor )
    768812                                        {
    769813                                                var selection = editor.getSelection();
    770                                                 deleteColumns( selection );
     814                                                var element = deleteColumns( selection );
     815                                                element &&  placeCursorInCell( element, true );
    771816                                        }
    772817                                } );
    773818
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy