Skip to content
Permalink
Browse files

Merge branch 't/12726' into major

  • Loading branch information...
Reinmar committed Dec 4, 2014
2 parents d06d1f5 + 61e7944 commit 47f8617f826f7aefa165509af19f76dcf6373b52
Showing with 40 additions and 14 deletions.
  1. +14 −14 core/editable.js
  2. +26 −0 tests/core/editable/insertion.js
@@ -238,6 +238,8 @@
* @param {String} text
*/
insertText: function( text ) {
// Focus the editor before calling transformPlainTextToHtml. (#12726)
this.editor.focus();
this.insertHtml( this.transformPlainTextToHtml( text ), 'text' );
},

@@ -283,12 +285,15 @@
* @param {String} [mode='html'] See {@link CKEDITOR.editor#method-insertHtml}'s param.
*/
insertHtmlIntoSelection: function( data, mode ) {
var editor = this.editor;

editor.focus();
editor.fire( 'saveSnapshot' );

// HTML insertion only considers the first range.
// Note: getRanges will be overwritten for tests since we want to test
// custom ranges and bypass native selections.
var range = this.editor.getSelection().getRanges()[ 0 ];

beforeInsert( this );
// custom ranges and bypass native selections.
var range = editor.getSelection().getRanges()[ 0 ];

// Default mode is 'html'.
insert( this, mode || 'html', data, range );
@@ -402,11 +407,13 @@
* @param {CKEDITOR.dom.element} element The element to be inserted.
*/
insertElementIntoSelection: function( element ) {
var editor = this.editor;

// Prepare for the insertion. For example - focus editor (#11848).
beforeInsert( this );
editor.focus();
editor.fire( 'saveSnapshot' );

var editor = this.editor,
enterMode = editor.activeEnterMode,
var enterMode = editor.activeEnterMode,
selection = editor.getSelection(),
range = selection.getRanges()[ 0 ],
elementName = element.getName(),
@@ -2012,13 +2019,6 @@
return insert;
} )();

function beforeInsert( editable ) {
// TODO: For unknown reason we must call directly on the editable to put the focus immediately.
editable.editor.focus();

editable.editor.fire( 'saveSnapshot' );
}

function afterInsert( editable ) {
var editor = editable.editor;

@@ -108,6 +108,32 @@
// Just to be sure that test is correct.
assert.areSame( 2, toHtml, 'toHtml was fired twice' );
} );
},

'test insertHtml without focus': function() {
bender.editorBot.create( {
name: 'test_inserthtml_no_focus',
config: {
allowedContent: true
}
}, function( bot ) {
bot.editor.insertHtml( '<p>foo</p>' );

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

'test insertText without focus': function() {
bender.editorBot.create( {
name: 'test_inserttext_no_focus',
config: {
allowedContent: true
}
}, function( bot ) {
bot.editor.insertText( 'bar' );

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

0 comments on commit 47f8617

Please sign in to comment.
You can’t perform that action at this time.