Ticket #4784: 4784_3.patch

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

     
    8585
    8686                return retval;
    8787        }
     88       
     89        function getFocusedCell( cellsToDelete ) {
     90                var i = 0,
     91                        last = cellsToDelete.length - 1,
     92                        database = {},
     93                        cell,focusedCell,
     94                        tr;
     95       
     96                while ( cell = cellsToDelete[ i++ ] )
     97                        CKEDITOR.dom.element.setMarker( database, cell, 'delete_cell', true );
     98               
     99                // 1.first we check left or right side focusable cell row by row;
     100                i = 0;
     101                while ( cell = cellsToDelete[ i++ ] )
     102                {
     103                        if ( ( focusedCell = cell.getPrevious() ) && !focusedCell.getCustomData( 'delete_cell' )                         
     104                          || ( focusedCell = cell.getNext()     ) && !focusedCell.getCustomData( 'delete_cell' ) )
     105                        {
     106                                CKEDITOR.dom.element.clearAllMarkers( database );
     107                                return focusedCell;
     108                        }
     109                }
    88110
     111                CKEDITOR.dom.element.clearAllMarkers( database );
     112
     113                // 2. then we check the toppest row (outside the selection area square) focusable cell
     114                tr = cellsToDelete[ 0 ].getParent();
     115                if ( tr = tr.getPrevious() )
     116                        return tr.getLast();
     117               
     118                // 3. last we check the lowerest  row focusable cell
     119                tr = cellsToDelete[ last ].getParent();
     120                if ( tr = tr.getNext() )
     121                        return tr.getChild( 0 );
     122
     123                return null;
     124        }
     125
    89126        function clearRow( $tr )
    90127        {
    91128                // Get the array of row's cells.
     
    277314                if ( selectionOrCell instanceof CKEDITOR.dom.selection )
    278315                {
    279316                        var cellsToDelete = getSelectedCells( selectionOrCell );
     317                        var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' );
     318                        var cellToFocus   = getFocusedCell( cellsToDelete );
     319
    280320                        for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- )
    281321                                deleteCells( cellsToDelete[ i ] );
     322                       
     323                        if ( cellToFocus )
     324                                placeCursorInCell( cellToFocus, true );
     325                        else if ( table )
     326                                table.remove();
    282327                }
    283328                else if ( selectionOrCell instanceof CKEDITOR.dom.element )
    284329                {
    285                         if ( selectionOrCell.getParent().getChildCount() == 1 )
    286                                 selectionOrCell.getParent().remove();
     330                        var tr = selectionOrCell.getParent();
     331                        if ( tr.getChildCount() == 1 )
     332                                tr.remove();
    287333                        else
    288334                                selectionOrCell.remove();
    289335                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy