Ticket #4851: 4851.patch

File 4851.patch, 2.0 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/tabletools/plugin.js

     
    123123        {
    124124                if ( selectionOrRow instanceof CKEDITOR.dom.selection )
    125125                {
    126                         var cells = getSelectedCells( selectionOrRow );
    127                         var rowsToDelete = [];
     126                        var cells = getSelectedCells( selectionOrRow ),
     127                                        cellsCount = cells.length,
     128                                        rowsToDelete = [],
     129                                        cursorPosition,
     130                                        previousRowIndex,
     131                                        nextRowIndex;
    128132
    129133                        // Queue up the rows - it's possible and likely that we have duplicates.
    130                         for ( var i = 0 ; i < cells.length ; i++ )
     134                        for ( var i = 0 ; i < cellsCount ; i++ )
    131135                        {
    132                                 var row = cells[ i ].getParent();
    133                                 rowsToDelete[ row.$.rowIndex ] = row;
     136                                var row = cells[ i ].getParent(),
     137                                                rowIndex = row.$.rowIndex;
     138
     139                                i == 0 && ( previousRowIndex = rowIndex - 1 );
     140                                rowsToDelete[ rowIndex ] = row;
     141                                i == cellsCount - 1 && ( nextRowIndex = rowIndex + 1 );
    134142                        }
    135143
     144                        var table = row.getAscendant( 'table' ),
     145                                        rows =  table.$.rows,
     146                                        rowCount = rows.length;
     147
     148                        // Where to put the cursor after rows been deleted?
     149                        // 1. Into next sibling row if any;
     150                        // 2. Into previous sibling row if any;
     151                        // 3. Into table's parent element.
     152                        cursorPosition = new CKEDITOR.dom.element(
     153                                        nextRowIndex < rowCount && table.$.rows[ nextRowIndex ] ||
     154                                        previousRowIndex > 0 && table.$.rows[ previousRowIndex ] ||
     155                                        table.$.parentNode );
     156
    136157                        for ( i = rowsToDelete.length ; i >= 0 ; i-- )
    137158                        {
    138159                                if ( rowsToDelete[ i ] )
    139160                                        deleteRows( rowsToDelete[ i ] );
    140161                        }
     162
     163                        return cursorPosition;
    141164                }
    142165                else if ( selectionOrRow instanceof CKEDITOR.dom.element )
    143166                {
     
    668691                                        exec : function( editor )
    669692                                        {
    670693                                                var selection = editor.getSelection();
    671                                                 deleteRows( selection );
     694                                                placeCursorInCell( deleteRows( selection ) );
    672695                                        }
    673696                                } );
    674697
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy