Ticket #979: 979.patch

File 979.patch, 4.5 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/keystrokes/plugin.js

     
    214214        [ CKEDITOR.CTRL + 73 /*I*/, 'italic' ],
    215215        [ CKEDITOR.CTRL + 85 /*U*/, 'underline' ],
    216216
     217        [ CKEDITOR.ALT + 38 /*Arrow Up*/, 'selectPreviousCell' ],
     218        [ CKEDITOR.ALT + 40 /*Arrow Down*/, 'selectNextCell' ],
     219
    217220        [ CKEDITOR.ALT + 109 /*-*/, 'toolbarCollapse' ],
    218221        [ CKEDITOR.ALT + 48 /*0*/, 'a11yHelp' ]
    219222];
  • _source/plugins/tab/plugin.js

     
    2727                        }
    2828                };
    2929
     30        function selectNextCellCommand( backward )
     31        {
     32                return {
     33                        editorFocus : false,
     34                        canUndo : false,
     35                        modes : { wysiwyg : 1 },
     36                        exec : function( editor )
     37                        {
     38                                if ( editor.focusManager.hasFocus )
     39                                {
     40                                        var sel = editor.getSelection(),
     41                                                        ancestor = sel.getCommonAncestor(),
     42                                                        cell;
     43
     44                                        if ( cell = ( ancestor.getAscendant( 'td', true ) || ancestor.getAscendant( 'th', true ) ) )
     45                                        {
     46                                                var resultRange = new CKEDITOR.dom.range( editor.document ),
     47                                                                next = CKEDITOR.tools.tryThese( function()
     48                                                                {
     49                                                                        var row = cell.getParent(),
     50                                                                                        next = row.$.cells[ cell.$.cellIndex + ( backward ? - 1 : 1 ) ];
     51
     52                                                                        // Invalid any empty value.
     53                                                                        next.parentNode.parentNode;
     54                                                                        return next;
     55                                                                },
     56                                                                function()
     57                                                                {
     58                                                                        var row = cell.getParent(),
     59                                                                                        table = row.getAscendant( 'table' ),
     60                                                                                        nextRow = table.$.rows[ row.$.rowIndex + ( backward ? - 1 : 1 ) ];
     61
     62                                                                        return nextRow.cells[ backward? nextRow.cells.length -1 : 0 ];
     63                                                                });
     64
     65                                                // Clone one more row at the end of table and select the first newly established cell.
     66                                                if ( ! ( next || backward ) )
     67                                                {
     68                                                        var table = cell.getAscendant( 'table' ).$,
     69                                                                        cells = cell.getParent().$.cells;
     70
     71                                                        var newRow = new CKEDITOR.dom.element( table.insertRow( -1 ), editor.document );
     72
     73                                                        for ( var i = 0, count = cells.length ; i < count; i++ )
     74                                                        {
     75                                                                var newCell = newRow.append( new CKEDITOR.dom.element(
     76                                                                                cells[ i ], editor.document ).clone( false, false ) );
     77                                                                !CKEDITOR.env.ie && newCell.appendBogus();
     78                                                        }
     79
     80                                                        resultRange.moveToElementEditStart( newRow );
     81                                                }
     82                                                else if ( next )
     83                                                        resultRange.moveToElementEditStart( new CKEDITOR.dom.element( next ) );
     84                                                else
     85                                                        return true;
     86
     87                                                resultRange.select( true );
     88                                                return true;
     89                                        }
     90                                }
     91                                return false;
     92                        }
     93                };
     94        }
     95
    3096        CKEDITOR.plugins.add( 'tab',
    3197        {
    3298                requires : [ 'keystrokes' ],
    3399
    34100                init : function( editor )
    35101                {
    36                         var tabSpaces = editor.config.tabSpaces || 0,
     102                        var tabTools = editor.config.enableTabKeyTools !== false,
     103                                tabSpaces = editor.config.tabSpaces || 0,
    37104                                tabText = '';
    38105
    39106                        while ( tabSpaces-- )
     
    51118                                        });
    52119                        }
    53120
     121                        if ( tabTools )
     122                        {
     123                                editor.on( 'key', function( ev )
     124                                {
     125                                        if ( ev.data.keyCode == 9 && editor.execCommand( 'selectNextCell' ) ||  // TAB
     126                                                        ev.data.keyCode == ( CKEDITOR.SHIFT + 9 ) && editor.execCommand( 'selectPreviousCell' ) )       // SHIFT+TAB
     127                                                ev.cancel();
     128                                })
     129                        }
     130
    54131                        if ( CKEDITOR.env.webkit )
    55132                        {
    56133                                editor.on( 'key', function( ev )
     
    73150
    74151                        editor.addCommand( 'blur', CKEDITOR.tools.extend( blurCommand, meta ) );
    75152                        editor.addCommand( 'blurBack', CKEDITOR.tools.extend( blurBackCommand, meta ) );
     153                        editor.addCommand( 'selectNextCell', selectNextCellCommand() );
     154                        editor.addCommand( 'selectPreviousCell', selectNextCellCommand( true ) );
    76155                }
    77156        });
    78157})();
     
    259338 * @example
    260339 * config.tabSpaces = 4;
    261340 */
     341
     342/**
     343 * Allow context-sensitive tab key behaviors, including the following scenarios:
     344 * <h5>When selection is anchored inside <b>table cells</b>:</h5>
     345 * <ul>
     346 *              <li>If TAB is pressed, select the contents of the "next" cell. If in the last cell in the table, add a new row to it and focus its first cell.</li>
     347 *              <li>If SHIFT+TAB is pressed, select the contents of the "previous" cell. Do nothing when it's in the first cell.</li>
     348 * </ul>
     349 * @name CKEDITOR.config.enableTabKeyTools
     350 * @type Boolean
     351 * @default true
     352 * @example
     353 * config.enableTabKeyTools = false;
     354 */
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy