Ticket #5367: 5367_2.patch

File 5367_2.patch, 8.8 KB (added by Garry Yao, 13 years ago)
  • _source/core/editor.js

     
    755755                        this.fire( 'insertHtml', data );
    756756                },
    757757
     758                /*
     759                 * Insert text content into the currently selected position in the
     760                 * editor, in WYSIWYG mode, styles of the selected element will be applied to the inserted text,
     761                 * spaces around the text will be leaving untouched.
     762                 * <strong>Note:</strong> two subsequent line-breaks will be translated into
     763                 * one enter-key in effect, result depends on {@link CKEDITOR.config.enterMode};
     764                 * A single line-break will be translated into per shift-enter-key correspondingly.
     765                 * @param {String} text Text to be inserted into the editor.
     766                 * @example
     767                 * CKEDITOR.instances.editor1.<b>insertText( ' line1 \n\n line2' )</b>;
     768                 */
     769                insertText : function( text )
     770                {
     771                        this.fire( 'insertText', text );
     772                },
     773
    758774                /**
    759775                 * Inserts an element into the currently selected position in the
    760776                 * editor.
  • _source/plugins/wysiwygarea/plugin.js

     
    102102                }
    103103        }
    104104
     105        function doInsertText( doc, text )
     106        {
     107                var selection = doc.getSelection(),
     108                        range = selection.getRanges()[ 0 ];
     109
     110                range.insertNode( new CKEDITOR.dom.text( text, doc ) );
     111                range.collapse();
     112                range.select();
     113        }
     114
     115        function doEnter( editor, mode, times, forceMode )
     116        {
     117                while ( times-- )
     118                {
     119                        CKEDITOR.plugins.enterkey[ mode == CKEDITOR.ENTER_BR ? 'enterBr' : 'enterBlock' ]
     120                                        ( editor, mode, null, forceMode );
     121                }
     122        }
     123
     124        function onInsertText( evt )
     125        {
     126                if ( this.mode == 'wysiwyg' )
     127                {
     128                        this.focus();
     129                        this.fire( 'saveSnapshot' );
     130
     131                        var text = evt.data,
     132                                sel = this.getSelection(),
     133                                mode = sel.getStartElement().hasAscendant( 'pre', true ) ?
     134                                           CKEDITOR.ENTER_BR : this.config.enterMode,
     135                                isEnterBrMode = mode == CKEDITOR.ENTER_BR,
     136                                doc = this.document,
     137                                self = this,
     138                                line;
     139
     140                        // Make use of the browser to perform "extractContent".
     141                        if ( CKEDITOR.env.ie )
     142                                sel.getNative().createRange().pasteHTML( '' );
     143                        else
     144                        {
     145                                var markerId = 'cke_bm_' + CKEDITOR.tools.getNextNumber() + 'S';
     146                                doc.$.execCommand( 'insertHtml', false, CKEDITOR.env.gecko ?
     147                                                '<span id="' + markerId + '" data-cke-bookmark=1></span>' : '' );
     148
     149                                // Merge the fragile inline (contextual) elements  split by Gecko.
     150                                var bookmark = doc.getById( markerId ),
     151                                                previous = bookmark.getPrevious();
     152
     153                                if ( previous && previous.type == CKEDITOR.NODE_ELEMENT && previous.getName() in CKEDITOR.dtd.$inline )
     154                                        previous.mergeSiblings();
     155
     156                                var range = new CKEDITOR.dom.range( doc );
     157                                range.moveToBookmark( { serializable : 1 , startNode: markerId } );
     158                                range.select();
     159                        }
     160
     161                        text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );
     162
     163                        var startIndex = 0;
     164                        text.replace( /\n+/g, function( match, lastIndex )
     165                        {
     166                                line = text.substring( startIndex, lastIndex );
     167                                startIndex = lastIndex + match.length;
     168                                line.length && doInsertText( doc, line );
     169
     170                                var lineBreakNums = match.length,
     171                                        // Duo consequence line-break as a enter block.
     172                                                enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ),
     173                                        // Per link-break as a enter br.
     174                                                enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2;
     175
     176                                // Line-breaks are converted to editor enter key strokes.
     177                                doEnter( self, mode, enterBlockTimes );
     178                                doEnter( self, CKEDITOR.ENTER_BR, enterBrTimes, isEnterBrMode ? false : true );
     179                        } );
     180
     181                        // Insert the last text line of text.
     182                        line = text.substring( startIndex, text.length );
     183                        line.length && doInsertText( doc, line );
     184
     185                        this.fire( 'saveSnapshot' );
     186                }
     187        }
     188
    105189        function onInsertElement( evt )
    106190        {
    107191                if ( this.mode == 'wysiwyg' )
     
    9611045
    9621046                                        editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
    9631047                                        editor.on( 'insertElement', onInsertElement, null, null, 20 );
     1048                                        editor.on( 'insertText', onInsertText, null, null, 20 );
    9641049                                        // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189)
    9651050                                        editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
    9661051                                });
  • _source/core/dom/element.js

     
    721721                        var thisLength = thisAttribs.length,
    722722                                otherLength = otherAttribs.length;
    723723
    724                         if ( !CKEDITOR.env.ie && thisLength != otherLength )
    725                                 return false;
    726 
    727724                        for ( var i = 0 ; i < thisLength ; i++ )
    728725                        {
    729726                                var attribute = thisAttribs[ i ];
    730727
     728                                if ( attribute.nodeName == '_moz_dirty' )
     729                                        continue;
     730
    731731                                if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != 'data-cke-expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) )
    732732                                        return false;
    733733                        }
  • _source/plugins/specialchar/dialogs/specialchar.js

     
    1212        var dialog,
    1313                lang = editor.lang.specialChar;
    1414
    15         var insertSpecialChar = function ( specialChar )
    16         {
    17                 var selection = editor.getSelection(),
    18                         ranges = selection.getRanges( true ),
    19                         range, textNode;
    20 
    21                 editor.fire( 'saveSnapshot' );
    22 
    23                 for ( var i = ranges.length - 1; i >= 0 ; i-- )
    24                 {
    25                         range = ranges[ i ];
    26                         range.deleteContents();
    27 
    28                         textNode = CKEDITOR.dom.element.createFromHtml( specialChar );
    29                         range.insertNode( textNode );
    30                 }
    31 
    32                 if ( range )
    33                 {
    34                         range.moveToPosition( textNode, CKEDITOR.POSITION_AFTER_END );
    35                         range.select();
    36                 }
    37 
    38                 editor.fire( 'saveSnapshot' );
    39         };
    40 
    4115        var onChoice = function( evt )
    4216        {
    4317                var target, value;
     
    5125                        target.removeClass( "cke_light_background" );
    5226                        dialog.hide();
    5327
    54                         // Firefox has bug on insert chars into a element use its own API. (#5170)
    55                         if ( CKEDITOR.env.gecko )
    56                                 insertSpecialChar( value );
    57                         else
    58                                 editor.insertHtml( value );
     28                        editor.insertText( value );
    5929                }
    6030        };
    6131
  • _source/plugins/pastetext/plugin.js

     
    3737                }
    3838        };
    3939
    40         function doInsertText( doc, text )
    41         {
    42                 // Native text insertion.
    43                 if ( CKEDITOR.env.ie )
    44                 {
    45                         var selection = doc.selection;
    46                         if ( selection.type == 'Control' )
    47                                 selection.clear();
    48                         selection.createRange().pasteHTML( text );
    49                 }
    50                 else
    51                         doc.execCommand( 'inserthtml', false, text );
    52         }
    53 
    5440        // Register the plugin.
    5541        CKEDITOR.plugins.add( 'pastetext',
    5642        {
     
    8470                requires : [ 'clipboard' ]
    8571        });
    8672
    87         function doEnter( editor, mode, times, forceMode )
    88         {
    89                 while ( times-- )
    90                 {
    91                         CKEDITOR.plugins.enterkey[ mode == CKEDITOR.ENTER_BR ? 'enterBr' : 'enterBlock' ]
    92                                         ( editor, mode, null, forceMode );
    93                 }
    94         }
    95 
    96         CKEDITOR.editor.prototype.insertText = function( text )
    97         {
    98                 this.focus();
    99                 this.fire( 'saveSnapshot' );
    100 
    101                 var mode = this.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : this.config.enterMode,
    102                         isEnterBrMode = mode == CKEDITOR.ENTER_BR,
    103                         doc = this.document.$,
    104                         self = this,
    105                         line;
    106 
    107                 text = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );
    108 
    109                 var startIndex = 0;
    110                 text.replace( /\n+/g, function( match, lastIndex )
    111                  {
    112                         line = text.substring( startIndex, lastIndex );
    113                         startIndex = lastIndex + match.length;
    114                         line.length && doInsertText( doc, line );
    115 
    116                         var lineBreakNums = match.length,
    117                                 // Duo consequence line-break as a enter block.
    118                                 enterBlockTimes = isEnterBrMode ? 0 : Math.floor( lineBreakNums / 2 ),
    119                                 // Per link-break as a enter br.
    120                                 enterBrTimes = isEnterBrMode ? lineBreakNums : lineBreakNums % 2;
    121 
    122                         // Line-breaks are converted to editor enter key strokes.
    123                         doEnter( self, mode, enterBlockTimes );
    124                         doEnter( self, CKEDITOR.ENTER_BR, enterBrTimes, isEnterBrMode ? false : true );
    125                  });
    126 
    127                 // Insert the last text line of text.
    128                 line = text.substring( startIndex, text.length );
    129                 line.length && doInsertText( doc, line );
    130 
    131                 this.fire( 'saveSnapshot' );
    132         };
    13373})();
    13474
    13575
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy