+ try\r
+ {\r
+ $sel.createRange().pasteHTML( data );\r
+ }\r
+ catch (e) {}\r
+\r
+ if ( selIsLocked )\r
+ this.getSelection().lock();\r
+ }\r
+ else\r
+ this.document.$.execCommand( 'inserthtml', false, data );\r
+\r
+ // Webkit does not scroll to the cursor position after pasting (#5558)\r
+ if ( CKEDITOR.env.webkit )\r
+ {\r
+ selection = this.getSelection();\r
+ selection.scrollIntoView();\r
+ }\r
+ }\r
+\r
+ function doInsertText( text )\r
+ {\r
+ var selection = this.getSelection(),\r
+ mode = selection.getStartElement().hasAscendant( 'pre', true ) ?\r
+ CKEDITOR.ENTER_BR : this.config.enterMode,\r
+ isEnterBrMode = mode == CKEDITOR.ENTER_BR;\r
+\r
+ var html = CKEDITOR.tools.htmlEncode( text.replace( /\r\n|\r/g, '\n' ) );\r
+\r
+ // Convert leading and trailing whitespaces into \r
+ html = html.replace( /^[ \t]+|[ \t]+$/g, function( match, offset, s )\r
+ {\r
+ if ( match.length == 1 ) // one space, preserve it\r
+ return ' ';\r
+ else if ( !offset ) // beginning of block\r
+ return CKEDITOR.tools.repeat( ' ', match.length - 1 ) + ' ';\r
+ else // end of block\r
+ return ' ' + CKEDITOR.tools.repeat( ' ', match.length - 1 );\r
+ } );\r
+\r
+ // Convert subsequent whitespaces into \r
+ html = html.replace( /[ \t]{2,}/g, function ( match )\r
+ {\r
+ return CKEDITOR.tools.repeat( ' ', match.length - 1 ) + ' ';\r
+ } );\r
+\r
+ var paragraphTag = mode == CKEDITOR.ENTER_P ? 'p' : 'div';\r
+\r
+ // Two line-breaks create one paragraph.\r
+ if ( !isEnterBrMode )\r
+ {\r
+ html = html.replace( /(\n{2})([\s\S]*?)(?:$|\1)/g,\r
+ function( match, group1, text )\r
+ {\r
+ return '<'+paragraphTag + '>' + text + '</' + paragraphTag + '>';\r
+ });\r
+ }\r
+\r
+ // One <br> per line-break.\r
+ html = html.replace( /\n/g, '<br>' );\r
+\r
+ // Compensate padding <br> for non-IE.\r
+ if ( !( isEnterBrMode || CKEDITOR.env.ie ) )\r
+ {\r
+ html = html.replace( new RegExp( '<br>(?=</' + paragraphTag + '>)' ), function( match )\r
+ {\r
+ return CKEDITOR.tools.repeat( match, 2 );\r
+ } );\r
+ }\r
+\r
+ // Inline styles have to be inherited in Firefox.\r
+ if ( CKEDITOR.env.gecko || CKEDITOR.env.webkit )\r
+ {\r
+ var path = new CKEDITOR.dom.elementPath( selection.getStartElement() ),\r
+ context = [];\r
+\r
+ for ( var i = 0; i < path.elements.length; i++ )\r
+ {\r
+ var tag = path.elements[ i ].getName();\r
+ if ( tag in CKEDITOR.dtd.$inline )\r
+ context.unshift( path.elements[ i ].getOuterHtml().match( /^<.*?>/) );\r
+ else if ( tag in CKEDITOR.dtd.$block )\r
+ break;\r
+ }\r
+\r
+ // Reproduce the context by preceding the pasted HTML with opening inline tags.\r
+ html = context.join( '' ) + html;\r
+ }\r
+\r
+ doInsertHtml.call( this, html );\r
+ }\r
+\r
+ function doInsertElement( element )\r
+ {\r
+ var selection = this.getSelection(),\r
+ ranges = selection.getRanges(),\r
+ elementName = element.getName(),\r
+ isBlock = CKEDITOR.dtd.$block[ elementName ];\r
+\r
+ var selIsLocked = selection.isLocked;\r
+\r
+ if ( selIsLocked )\r
+ selection.unlock();\r
+\r
+ var range, clone, lastElement, bookmark;\r
+\r
+ for ( var i = ranges.length - 1 ; i >= 0 ; i-- )\r
+ {\r
+ range = ranges[ i ];\r
+\r
+ if ( !range.checkReadOnly() )\r