Navigation Menu

Skip to content

Commit

Permalink
Merge branch 't/12726' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Dec 4, 2014
2 parents d06d1f5 + 61e7944 commit 47f8617
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core/editable.js
Expand Up @@ -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' );
},

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;

Expand Down
26 changes: 26 additions & 0 deletions tests/core/editable/insertion.js
Expand Up @@ -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.