Ticket #3708: 3708.patch

File 3708.patch, 2.2 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/styles/plugin.js

     
    283283                        // Create the element to be inserted in the DOM.
    284284                        var collapsedElement = getElement( this, document );
    285285
     286                        // Webkit require actual text content to move selection into
     287                        // this collapsed element. (#3708)
     288                        if( CKEDITOR.env.webkit )
     289                        {
     290                                var bogusText = collapsedElement.append(  document.createText('\ufeff') );
     291                                function onInputRemoveBogus( evt )
     292                                {
     293                                        document.removeListener( 'keyup', arguments.callee );
     294                                        document.removeListener( 'mouseup', arguments.callee );
     295
     296                                        var keyCode = evt.data.getKey(),
     297                                                bogusText = collapsedElement.getFirst();
     298                                        // Ignore control keys.
     299                                        if ( keyCode == 17  // Ctrl
     300                                                 || keyCode == 16 // Shift
     301                                                 || keyCode == 18 // Alt
     302                                                )
     303                                        {
     304                                                checkNextInput();
     305                                                return;
     306                                        }
     307
     308                                        // Followed by any alphabatic key pressed indicate now the
     309                                        // style element is no longer collpased.
     310                                        if( /\w/.test( String.fromCharCode( keyCode ) ) )
     311                                        {
     312                                                // The bogus text has been merged with newly inputed char,
     313                                                // split it out, move selection after it, then remove it.
     314                                                bogusText = bogusText.split( 1 ).getPrevious();
     315                                                range.moveToPosition( bogusText, CKEDITOR.POSITION_AFTER_END );
     316                                                bogusText.remove();
     317                                                range.select();
     318                                        }
     319                                        else
     320                                                bogusText.remove();
     321                                }
     322                                function checkNextInput()
     323                                {
     324                                        document.on( 'keyup', onInputRemoveBogus );
     325                                        document.on( 'mouseup', onInputRemoveBogus );
     326                                }
     327                                // It's possible that we're now inside a key event thread,
     328                                // e.g. shortcutKey, so defer to skip this 'keyup'.
     329                                window.setTimeout(  checkNextInput, 300 );
     330                        }
    286331                        // Insert the empty element into the DOM at the range position.
    287332                        range.insertNode( collapsedElement );
    288333
     334
    289335                        // Place the selection right inside the empty element.
    290336                        range.moveToPosition( collapsedElement, CKEDITOR.POSITION_BEFORE_END );
    291337
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy