Skip to content

Commit

Permalink
Merge branch 't/12793' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Mar 10, 2015
2 parents d370237 + 649796e commit 9980296
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/editable.js
Expand Up @@ -1619,7 +1619,7 @@

var context = that.blockLimit.getName();

// Wrap data to be inserted, to avoid loosing leading whitespaces
// Wrap data to be inserted, to avoid losing leading whitespaces
// when going through the below procedure.
if ( /^\s+|\s+$/.test( data ) && 'span' in CKEDITOR.dtd[ context ] ) {
var protect = '<span data-cke-marker="1">&nbsp;</span>';
Expand All @@ -1632,6 +1632,7 @@
data = that.editor.dataProcessor.toHtml( data, {
context: null,
fixForBody: false,
protectedWhitespaces: !!protect,
dontFilter: that.dontFilter,
// Use the current, contextual settings.
filter: that.editor.activeFilter,
Expand Down
9 changes: 7 additions & 2 deletions core/htmldataprocessor.js
Expand Up @@ -224,11 +224,13 @@
* @param {Boolean} [options.dontFilter] Do not filter data with {@link CKEDITOR.filter} (note: transformations
* will be still applied).
* @param {Number} [options.enterMode] When specified it will be used instead of the {@link CKEDITOR.editor#enterMode main enterMode}.
* @param {Boolean} [options.protectedWhitespaces] Indicates that content has been wrapped with `span` elements to preserve
* leading and trailing whitespaces. Option used by the {@link CKEDITOR.editor#insertHtml} method.
* @returns {String}
*/
toHtml: function( data, options, fixForBody, dontFilter ) {
var editor = this.editor,
context, filter, enterMode;
context, filter, enterMode, protectedWhitespaces;

// Typeof null == 'object', so check truthiness of options too.
if ( options && typeof options == 'object' ) {
Expand All @@ -237,6 +239,7 @@
dontFilter = options.dontFilter;
filter = options.filter;
enterMode = options.enterMode;
protectedWhitespaces = options.protectedWhitespaces;
}
// Backward compatibility. Since CKEDITOR 4.3 every option was a separate argument.
else {
Expand All @@ -253,7 +256,8 @@
fixForBody: fixForBody,
dontFilter: dontFilter,
filter: filter || editor.filter,
enterMode: enterMode || editor.enterMode
enterMode: enterMode || editor.enterMode,
protectedWhitespaces: protectedWhitespaces
} ).dataValue;
},

Expand Down Expand Up @@ -989,6 +993,7 @@
* @param {Boolean} data.dontFilter See {@link CKEDITOR.htmlDataProcessor#toHtml} The `dontFilter` argument.
* @param {Boolean} data.filter See {@link CKEDITOR.htmlDataProcessor#toHtml} The `filter` argument.
* @param {Boolean} data.enterMode See {@link CKEDITOR.htmlDataProcessor#toHtml} The `enterMode` argument.
* @param {Boolean} [data.protectedWhitespaces] See {@link CKEDITOR.htmlDataProcessor#toHtml} The `protectedWhitespaces` argument.
*/

/**
Expand Down
10 changes: 8 additions & 2 deletions plugins/widget/plugin.js
Expand Up @@ -2662,8 +2662,14 @@
}

// Used to determine whether only widget was pasted.
processedWidgetOnly = evt.data.dataValue.children.length == 1 &&
Widget.isParserWidgetWrapper( evt.data.dataValue.children[ 0 ] );
if ( evt.data.protectedWhitespaces ) {
// Whitespaces are protected by wrapping content with spans. Take the middle node only.
processedWidgetOnly = evt.data.dataValue.children.length == 3 &&
Widget.isParserWidgetWrapper( evt.data.dataValue.children[ 1 ] );
} else {
processedWidgetOnly = evt.data.dataValue.children.length == 1 &&
Widget.isParserWidgetWrapper( evt.data.dataValue.children[ 0 ] );
}
}, null, null, 8 );

editor.on( 'dataReady', function() {
Expand Down
10 changes: 10 additions & 0 deletions tests/core/editable/insertion.js
Expand Up @@ -134,6 +134,16 @@

assert.areSame( '<p>bar</p>', bot.editor.getData(), 'text was inserted' );
} );
},

'test insertHtml sets options.protectedWhitespaces of dP.toHtml': function() {
var editor = this.editor;

editor.once( 'toHtml', function( evt ) {
assert.isTrue( evt.data.protectedWhitespaces );
} );

editor.insertHtml( ' foo ' );
}
} );
} )();
10 changes: 10 additions & 0 deletions tests/core/htmldataprocessor.js
Expand Up @@ -1010,6 +1010,16 @@
} ), 'br mode' );
},

'test toHtml options.protectedWhitespaces defaults falsy': function() {
var editor = this.editor;

editor.once( 'toHtml', function( evt ) {
assert.isUndefined( evt.data.protectedWhitespaces );
} );

editor.dataProcessor.toHtml( 'foo', {} );
},

'test leading br is removed by toDataFormat in ENTER_P and ENTER_DIV': function() {
var htmlDP = this.editor.dataProcessor,
opts = { enterMode: CKEDITOR.ENTER_P };
Expand Down
7 changes: 6 additions & 1 deletion tests/plugins/widget/nestedwidgets.js
Expand Up @@ -298,6 +298,11 @@

// #12008
'test pasting widget with nested editable into nested editable': function() {
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
assert.ignore();
return;
}

var editor = this.editors.editor,
bot = this.editorBots.editor;

Expand Down Expand Up @@ -340,4 +345,4 @@
} );
}
} );
} )();
} )();

0 comments on commit 9980296

Please sign in to comment.