Skip to content

Commit 47f8617

Browse files
committed
Merge branch 't/12726' into major
2 parents d06d1f5 + 61e7944 commit 47f8617

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

core/editable.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@
238238
* @param {String} text
239239
*/
240240
insertText: function( text ) {
241+
// Focus the editor before calling transformPlainTextToHtml. (#12726)
242+
this.editor.focus();
241243
this.insertHtml( this.transformPlainTextToHtml( text ), 'text' );
242244
},
243245

@@ -283,12 +285,15 @@
283285
* @param {String} [mode='html'] See {@link CKEDITOR.editor#method-insertHtml}'s param.
284286
*/
285287
insertHtmlIntoSelection: function( data, mode ) {
288+
var editor = this.editor;
289+
290+
editor.focus();
291+
editor.fire( 'saveSnapshot' );
292+
286293
// HTML insertion only considers the first range.
287294
// Note: getRanges will be overwritten for tests since we want to test
288-
// custom ranges and bypass native selections.
289-
var range = this.editor.getSelection().getRanges()[ 0 ];
290-
291-
beforeInsert( this );
295+
// custom ranges and bypass native selections.
296+
var range = editor.getSelection().getRanges()[ 0 ];
292297

293298
// Default mode is 'html'.
294299
insert( this, mode || 'html', data, range );
@@ -402,11 +407,13 @@
402407
* @param {CKEDITOR.dom.element} element The element to be inserted.
403408
*/
404409
insertElementIntoSelection: function( element ) {
410+
var editor = this.editor;
411+
405412
// Prepare for the insertion. For example - focus editor (#11848).
406-
beforeInsert( this );
413+
editor.focus();
414+
editor.fire( 'saveSnapshot' );
407415

408-
var editor = this.editor,
409-
enterMode = editor.activeEnterMode,
416+
var enterMode = editor.activeEnterMode,
410417
selection = editor.getSelection(),
411418
range = selection.getRanges()[ 0 ],
412419
elementName = element.getName(),
@@ -2012,13 +2019,6 @@
20122019
return insert;
20132020
} )();
20142021

2015-
function beforeInsert( editable ) {
2016-
// TODO: For unknown reason we must call directly on the editable to put the focus immediately.
2017-
editable.editor.focus();
2018-
2019-
editable.editor.fire( 'saveSnapshot' );
2020-
}
2021-
20222022
function afterInsert( editable ) {
20232023
var editor = editable.editor;
20242024

tests/core/editable/insertion.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,32 @@
108108
// Just to be sure that test is correct.
109109
assert.areSame( 2, toHtml, 'toHtml was fired twice' );
110110
} );
111+
},
112+
113+
'test insertHtml without focus': function() {
114+
bender.editorBot.create( {
115+
name: 'test_inserthtml_no_focus',
116+
config: {
117+
allowedContent: true
118+
}
119+
}, function( bot ) {
120+
bot.editor.insertHtml( '<p>foo</p>' );
121+
122+
assert.areSame( '<p>foo</p>', bot.editor.getData(), 'HTML was inserted' );
123+
} );
124+
},
125+
126+
'test insertText without focus': function() {
127+
bender.editorBot.create( {
128+
name: 'test_inserttext_no_focus',
129+
config: {
130+
allowedContent: true
131+
}
132+
}, function( bot ) {
133+
bot.editor.insertText( 'bar' );
134+
135+
assert.areSame( '<p>bar</p>', bot.editor.getData(), 'text was inserted' );
136+
} );
111137
}
112138
} );
113139
} )();

0 commit comments

Comments
 (0)