Skip to content

Commit

Permalink
Merge branch 't/13042' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Apr 3, 2015
2 parents 5f29948 + 38ddd94 commit 1b974b7
Show file tree
Hide file tree
Showing 21 changed files with 824 additions and 246 deletions.
34 changes: 24 additions & 10 deletions core/editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
* @param {String} data The HTML to be inserted.
* @param {String} [mode='html'] See {@link CKEDITOR.editor#method-insertHtml}'s param.
* @param {CKEDITOR.dom.range} [range] If specified the HTML will be inserted into the range
* instead of into the selection. Introduced in CKEditor 4.5.
* instead of into the selection. The selection will be placed at the end of insertion (like in the normal case).
* Introduced in CKEditor 4.5.
*/
insertHtml: function( data, mode, range ) {
var editor = this.editor;
Expand Down Expand Up @@ -659,9 +660,11 @@
*
* @since 4.5
* @param {CKEDITOR.dom.range} range
* @returns {CKEDITOR.dom.documentFragment}
* @param {Boolean} [removeEmptyBlock=false] See {@link CKEDITOR.editor#extractSelectedHtml}'s parameter.
* Note that the range will not be modified if this parameter is set to `true`.
* @returns {CKEDITOR.dom.documentFragment} The extracted fragment of the editable contents.
*/
extractHtmlFromRange: function( range ) {
extractHtmlFromRange: function( range, removeEmptyBlock ) {
var helpers = extractHtmlFromRangeHelpers,
that = {
range: range,
Expand Down Expand Up @@ -736,15 +739,26 @@
helpers.table.purge( that, this );
helpers.block.merge( that, this );

// Auto paragraph, if needed.
helpers.autoParagraph( this.editor, range );
// Remove empty block, duh!
if ( removeEmptyBlock ) {
var path = range.startPath();

// Let's have a bogus next to the caret, if needed.
if ( isEmpty( range.startContainer ) )
range.startContainer.appendBogus();
// <p><b>^</b></p> is empty block.
if ( range.checkStartOfBlock() && range.checkEndOfBlock() && path.block && !range.root.equals( path.block ) ) {
range.moveToPosition( path.block, CKEDITOR.POSITION_BEFORE_START );
path.block.remove();
}
} else {
// Auto paragraph, if needed.
helpers.autoParagraph( this.editor, range );

// Let's have a bogus next to the caret, if needed.
if ( isEmpty( range.startContainer ) )
range.startContainer.appendBogus();
}

// Merge inline siblings if any around the caret.
range.startContainer.mergeSiblings( 1 );
range.startContainer.mergeSiblings();

return extractedFragment;
},
Expand Down Expand Up @@ -799,7 +813,7 @@
}, this );

this.attachListener( editor, 'insertHtml', function( evt ) {
this.insertHtml( evt.data.dataValue, evt.data.mode );
this.insertHtml( evt.data.dataValue, evt.data.mode, evt.data.range );
}, this );
this.attachListener( editor, 'insertElement', function( evt ) {
this.insertElement( evt.data );
Expand Down
32 changes: 20 additions & 12 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,16 +1037,18 @@
* @param {String} html HTML code to be inserted into the editor.
* @param {String} [mode='html'] The mode in which the HTML code will be inserted. One of the following:
*
* * `"html"` &ndash; The content being inserted will completely override the styles
* at the selected position.
* * `"unfiltered_html"` &ndash; Like `"html"` but the content is not filtered with {@link CKEDITOR.filter}.
* * `"text"` &ndash; The content being inserted will inherit the styles applied in
* * `'html'` &ndash; The content being inserted will completely override the styles at the selected position.
* * `'unfiltered_html'` &ndash; Like `'html'` but the content is not filtered with {@link CKEDITOR.filter}.
* * `'text'` &ndash; The content being inserted will inherit the styles applied in
* the selected position. This mode should be used when inserting "htmlified" plain text
* (HTML without inline styles and styling elements like
* `<b/>`, `<strong/>`, `<span style="..."/>`).
* (HTML without inline styles and styling elements like `<b>`, `<strong>`, `<span style="...">`).
*
* @param {CKEDITOR.dom.range} [range] If specified the HTML will be inserted into the range
* instead of into the selection. The selection will be placed at the end of insertion (like in the normal case).
* Introduced in CKEditor 4.5.
*/
insertHtml: function( html, mode ) {
this.fire( 'insertHtml', { dataValue: html, mode: mode } );
insertHtml: function( html, mode, range ) {
this.fire( 'insertHtml', { dataValue: html, mode: mode, range: range } );
},

/**
Expand Down Expand Up @@ -1133,9 +1135,12 @@
*
* @since 4.5
* @param {Boolean} [toString] If `true`, then a stringified HTML will be returned.
* @returns {CKEDITOR.dom.documentFragment/String}
* @param {Boolean} [removeEmptyBlock=false] Default `false` means that the function will keep empty block (if the
* whole content was removed) or it will create it (if block element was removed) and set the selection in that block.
* If `true` the empty will be removed or not created. In this case the function will not handle the selection.
* @returns {CKEDITOR.dom.documentFragment/String/null}
*/
extractSelectedHtml: function( toString ) {
extractSelectedHtml: function( toString, removeEmptyBlock ) {
var editable = this.editable(),
ranges = this.getSelection().getRanges();

Expand All @@ -1144,9 +1149,11 @@
}

var range = ranges[ 0 ],
docFragment = editable.extractHtmlFromRange( range );
docFragment = editable.extractHtmlFromRange( range, removeEmptyBlock );

this.getSelection().selectRanges( [ range ] );
if ( !removeEmptyBlock ) {
this.getSelection().selectRanges( [ range ] );
}

return toString ? docFragment.getHtml() : docFragment;
},
Expand Down Expand Up @@ -1825,6 +1832,7 @@ CKEDITOR.ELEMENT_MODE_INLINE = 3;
* @param data
* @param {String} data.mode The mode in which the data is inserted (see {@link #method-insertHtml}).
* @param {String} data.dataValue The HTML code to insert.
* @param {CKEDITOR.dom.range} [data.range] See {@link #method-insertHtml}'s `range` parameter.
*/

/**
Expand Down
Loading

0 comments on commit 1b974b7

Please sign in to comment.