Skip to content

Commit

Permalink
Editor must be focused before retrieving range and before transformin…
Browse files Browse the repository at this point in the history
…g text to HTML what requires context.
  • Loading branch information
Reinmar committed Dec 4, 2014
1 parent ce9e15b commit 61e7944
Showing 1 changed file with 14 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

0 comments on commit 61e7944

Please sign in to comment.