Ticket #5367: 5367_2.patch
File 5367_2.patch, 8.8 KB (added by , 13 years ago) |
---|
-
_source/core/editor.js
755 755 this.fire( 'insertHtml', data ); 756 756 }, 757 757 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 758 774 /** 759 775 * Inserts an element into the currently selected position in the 760 776 * editor. -
_source/plugins/wysiwygarea/plugin.js
102 102 } 103 103 } 104 104 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 105 189 function onInsertElement( evt ) 106 190 { 107 191 if ( this.mode == 'wysiwyg' ) … … 961 1045 962 1046 editor.on( 'insertHtml', onInsertHtml, null, null, 20 ); 963 1047 editor.on( 'insertElement', onInsertElement, null, null, 20 ); 1048 editor.on( 'insertText', onInsertText, null, null, 20 ); 964 1049 // Auto fixing on some document structure weakness to enhance usabilities. (#3190 and #3189) 965 1050 editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 ); 966 1051 }); -
_source/core/dom/element.js
721 721 var thisLength = thisAttribs.length, 722 722 otherLength = otherAttribs.length; 723 723 724 if ( !CKEDITOR.env.ie && thisLength != otherLength )725 return false;726 727 724 for ( var i = 0 ; i < thisLength ; i++ ) 728 725 { 729 726 var attribute = thisAttribs[ i ]; 730 727 728 if ( attribute.nodeName == '_moz_dirty' ) 729 continue; 730 731 731 if ( ( !CKEDITOR.env.ie || ( attribute.specified && attribute.nodeName != 'data-cke-expando' ) ) && attribute.nodeValue != otherElement.getAttribute( attribute.nodeName ) ) 732 732 return false; 733 733 } -
_source/plugins/specialchar/dialogs/specialchar.js
12 12 var dialog, 13 13 lang = editor.lang.specialChar; 14 14 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 41 15 var onChoice = function( evt ) 42 16 { 43 17 var target, value; … … 51 25 target.removeClass( "cke_light_background" ); 52 26 dialog.hide(); 53 27 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 ); 59 29 } 60 30 }; 61 31 -
_source/plugins/pastetext/plugin.js
37 37 } 38 38 }; 39 39 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 else51 doc.execCommand( 'inserthtml', false, text );52 }53 54 40 // Register the plugin. 55 41 CKEDITOR.plugins.add( 'pastetext', 56 42 { … … 84 70 requires : [ 'clipboard' ] 85 71 }); 86 72 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 };133 73 })(); 134 74 135 75