Ticket #6659: 6659.patch

File 6659.patch, 4.4 KB (added by Martin, 13 years ago)
  • _source/plugins/keystrokes/plugin.js

     
    138138                        // keypress. So we must do a longer trip in those cases.
    139139                        if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
    140140                                domObject.on( 'keypress', onKeyPress, this );
     141                },
     142
     143                getCancelStatus : function( domObject )
     144                {
     145                        return cancel;
    141146                }
     147
    142148        };
    143149})();
    144150
  • _source/plugins/list/plugin.js

     
    694694                        // Register the state changing handlers.
    695695                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, numberedListCommand ) );
    696696                        editor.on( 'selectionChange', CKEDITOR.tools.bind( onSelectionChange, bulletedListCommand ) );
     697
     698
     699                        var stopType;
     700
     701            editor.on('contentDom',function(evt)
     702                        {
     703                                editor.document.on( 'keydown' , function(evt)
     704                                {
     705                                        var blacklistKeyCodes = { 37:1, 38:1, 39:1, 40:1, // Arrows: L, T, R, B
     706                                                                                          35:1, 36:1,                // END, HOME
     707                                                                                          33:1, 34:1                     // PAGE UP, PAGE DOWN
     708                                                                                        };
     709
     710                                        var keyCode = evt.data.getKey();
     711
     712                                        //reset flag
     713                                        stopType = false;
     714
     715                                        if( keyCode in blacklistKeyCodes )
     716                                                stopType = true;
     717                                })
     718
     719                                editor.document.on( 'keypress' , function ( evt )
     720                                {
     721                                        if( CKEDITOR.env.gecko )
     722                                        {
     723                                                //check if it is special code from keystroke
     724                                                var keystrokeHandler = editor.keystrokeHandler;
     725
     726                                                //get status of cancel flag from keystroke
     727                                                if( keystrokeHandler.getCancelStatus() )
     728                                                        return;
     729
     730                                                var ranges = editor.getSelection().getRanges();
     731
     732                                                for ( var i = 0 ; i < ranges.length ; i++ )
     733                                                {
     734                                                        var range = ranges[i];
     735
     736                                                        if( !range.startContainer.equals( range.endContainer ) )
     737                                                        {
     738                                                                var startOfBlock = range.checkStartOfBlock(),
     739                                                                        endOfBlock = range.checkEndOfBlock();
     740
     741                                                                var domEvent = evt.data;
     742
     743                                                                //catch inserted key
     744                                                                var key = domEvent.getKey()
     745
     746
     747                                                                //execute functionality only if selection is on start or on end of block in other case browser work correct
     748                                                                if( !stopType && ( startOfBlock || endOfBlock ) )
     749                                                                {
     750                                                                        range.deleteContents();
     751
     752                                                                        //get inserted char
     753                                                                        var myChar = String.fromCharCode( key );
     754
     755                                                                        var temp = new CKEDITOR.dom.text( myChar );
     756                                                                        range = editor.getSelection().getRanges()[0];
     757                                                                        range.insertNode( temp );
     758
     759                                                                        range.setStartAfter( temp );
     760
     761                                                                        var currentNode;
     762                                                                        var walker = new CKEDITOR.dom.walker( range );
     763
     764                                                                        //looking for list child
     765                                                                        walker.evaluator = function(node){
     766                                                                                return ( node.getParent().getName() in listNodeNames )
     767                                                                        }
     768
     769                                                                        while( currentNode = walker.next() )
     770                                                                        {
     771                                                                                //get nested list content
     772                                                                                var subList = currentNode.getFirst( function( node ){ return node.type == CKEDITOR.NODE_ELEMENT && node.is( 'ol', 'ul' ); } );
     773
     774                                                                                //check if list has empty items
     775                                                                                if( subList )
     776                                                                                {
     777                                                                                        var children = subList.getChildren(),
     778                                                                                        count = children.count(),
     779                                                                                        child;
     780
     781                                                                                        for ( i = count - 1 ; i >= 0 ; i-- )
     782                                                                                        {
     783                                                                                                //look for empty list item
     784                                                                                                if ( ( child = children.getItem( i ) ) && child.is && child.is( 'li' ) && child.getText() != ''  )
     785                                                                                                {
     786                                                                                                        //move list content
     787                                                                                                        var newParent = temp.getAscendant( 'li', true );
     788
     789                                                                                                        //move children of nested list. we dont check nested list contains just move them
     790                                                                                                        if( newParent )
     791                                                                                                                subList.move( newParent );
     792
     793                                                                                                        break;
     794                                                                                                }
     795                                                                                        }
     796                                                                                }
     797
     798                                                                                //remove unnecessary node
     799                                                                                currentNode.remove();
     800
     801                                                                                //update range
     802                                                                                var ascendant = temp.getAscendant( 'li', true );
     803
     804                                                                                if( ascendant )
     805                                                                                 range.moveToElementEditEnd( ascendant );
     806
     807                                                                                range.select();
     808                                                                        }
     809                                                                        evt.data.preventDefault();
     810                                                                }
     811                                                        }
     812                                                }
     813                                        }
     814                                })
     815                        })
    697816                },
    698817
    699818                afterInit : function ( editor )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy