Ticket #5577: 5577_3.patch
File 5577_3.patch, 3.1 KB (added by , 14 years ago) |
---|
-
_source/plugins/tabletools/plugin.js
86 86 return retval; 87 87 } 88 88 89 function getFocus edCell( cellsToDelete ) {89 function getFocusElementAfterDelCells( cellsToDelete ) { 90 90 var i = 0, 91 91 last = cellsToDelete.length - 1, 92 92 database = {}, … … 247 247 cell.insertAfter( baseCell ); 248 248 } 249 249 } 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 ); 250 261 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 251 289 function deleteColumns( selectionOrCell ) 252 290 { 253 291 if ( selectionOrCell instanceof CKEDITOR.dom.selection ) 254 292 { 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-- ) 257 297 { 258 298 if ( colsToDelete[ i ] ) 259 299 deleteColumns( colsToDelete[ i ] ); 260 300 } 301 302 return elementToFocus; 261 303 } 262 304 else if ( selectionOrCell instanceof CKEDITOR.dom.element ) 263 305 { 264 306 // Get the cell's table. 265 307 var table = selectionOrCell.getAscendant( 'table' ); 308 if ( !table ) 309 return; 266 310 267 311 // Get the cell index. 268 312 var cellIndex = selectionOrCell.$.cellIndex; … … 315 359 { 316 360 var cellsToDelete = getSelectedCells( selectionOrCell ); 317 361 var table = cellsToDelete[ 0 ] && cellsToDelete[ 0 ].getAscendant( 'table' ); 318 var cellToFocus = getFocus edCell( cellsToDelete );362 var cellToFocus = getFocusElementAfterDelCells( cellsToDelete ); 319 363 320 364 for ( var i = cellsToDelete.length - 1 ; i >= 0 ; i-- ) 321 365 deleteCells( cellsToDelete[ i ] ); … … 767 811 exec : function( editor ) 768 812 { 769 813 var selection = editor.getSelection(); 770 deleteColumns( selection ); 814 var element = deleteColumns( selection ); 815 element && placeCursorInCell( element, true ); 771 816 } 772 817 } ); 773 818