From 61e79440287b32b3b5355355e10c3a75c3ffb7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Thu, 4 Dec 2014 12:26:37 +0100 Subject: [PATCH] Editor must be focused before retrieving range and before transforming text to HTML what requires context. --- core/editable.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/editable.js b/core/editable.js index 5776b883859..fc2ef312ae2 100644 --- a/core/editable.js +++ b/core/editable.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;