Skip to content

Commit ddd2fb6

Browse files
committed
Merge branch 't/9521'
2 parents bf84cd5 + 57049a1 commit ddd2fb6

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

core/editable.js

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
* @see CKEDITOR.editor#insertHtml
156156
*/
157157
insertHtml: function( data, mode ) {
158+
beforeInsert( this );
158159
// Default mode is 'html'.
159160
insert( this, mode == 'text' ? 'text' : 'html', data );
160161
},
@@ -163,6 +164,8 @@
163164
* @see CKEDITOR.editor#insertText
164165
*/
165166
insertText: function( text ) {
167+
beforeInsert( this );
168+
166169
var editor = this.editor,
167170
mode = editor.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : editor.config.enterMode,
168171
isEnterBrMode = mode == CKEDITOR.ENTER_BR,
@@ -211,10 +214,7 @@
211214
* @see CKEDITOR.editor#insertElement
212215
*/
213216
insertElement: function( element ) {
214-
// TODO this should be gone after refactoring insertElement.
215-
// TODO: For unknown reason we must call directly on the editable to put the focus immediately.
216-
this.editor.focus();
217-
this.editor.fire( 'saveSnapshot' );
217+
beforeInsert( this );
218218

219219
var editor = this.editor,
220220
enterMode = editor.config.enterMode,
@@ -294,14 +294,8 @@
294294

295295
selection.selectRanges( [ range ] );
296296

297-
// TODO this should be gone after refactoring insertElement.
298-
// Save snaps after the whole execution completed.
299-
// This's a workaround for make DOM modification's happened after
300-
// 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
301-
// call.
302-
setTimeout( function() {
303-
editor.fire( 'saveSnapshot' );
304-
}, 0 );
297+
// Do not scroll after inserting, because Opera may fail on certain element (e.g. iframe/iframe.html).
298+
afterInsert( this, CKEDITOR.env.opera );
305299
},
306300

307301
/**
@@ -931,8 +925,6 @@
931925
// Inserts the given (valid) HTML into the range position (with range content deleted),
932926
// guarantee it's result to be a valid DOM tree.
933927
function insert( editable, type, data ) {
934-
beforeInsert( editable );
935-
936928
var editor = editable.editor,
937929
doc = editable.getDocument(),
938930
selection = editor.getSelection(),
@@ -993,13 +985,6 @@
993985
afterInsert( editable );
994986
}
995987

996-
function beforeInsert( editable ) {
997-
// TODO: For unknown reason we must call directly on the editable to put the focus immediately.
998-
editable.editor.focus();
999-
1000-
editable.editor.fire( 'saveSnapshot' );
1001-
}
1002-
1003988
// Prepare range to its data deletion.
1004989
// Delete its contents.
1005990
// Prepare it to insertion.
@@ -1319,21 +1304,6 @@
13191304

13201305
}
13211306

1322-
function afterInsert( editable ) {
1323-
var editor = editable.editor;
1324-
1325-
// Scroll using selection, not ranges, to affect native pastes.
1326-
editor.getSelection().scrollIntoView();
1327-
1328-
// Save snaps after the whole execution completed.
1329-
// This's a workaround for make DOM modification's happened after
1330-
// 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
1331-
// call.
1332-
setTimeout( function() {
1333-
editor.fire( 'saveSnapshot' );
1334-
}, 0 );
1335-
}
1336-
13371307
//
13381308
// HELPERS ------------------------------------------------------------
13391309
//
@@ -1611,6 +1581,28 @@
16111581
return insert;
16121582
})();
16131583

1584+
function beforeInsert( editable ) {
1585+
// TODO: For unknown reason we must call directly on the editable to put the focus immediately.
1586+
editable.editor.focus();
1587+
1588+
editable.editor.fire( 'saveSnapshot' );
1589+
}
1590+
1591+
function afterInsert( editable, noScroll ) {
1592+
var editor = editable.editor;
1593+
1594+
// Scroll using selection, not ranges, to affect native pastes.
1595+
!noScroll && editor.getSelection().scrollIntoView();
1596+
1597+
// Save snaps after the whole execution completed.
1598+
// This's a workaround for make DOM modification's happened after
1599+
// 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
1600+
// call.
1601+
setTimeout( function() {
1602+
editor.fire( 'saveSnapshot' );
1603+
}, 0 );
1604+
}
1605+
16141606
})();
16151607

16161608
/**

core/selection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@
405405
CKEDITOR.env.ie9Compat && editor.on( 'beforeDestroy', clearSelection, null, null, 9 );
406406
// Webkit's selection will mess up after the data loading.
407407
CKEDITOR.env.webkit && editor.on( 'setData', clearSelection );
408+
409+
// Invalidate locked selection when unloading DOM (e.g. after setData). (#9521)
410+
editor.on( 'contentDomUnload', function() {
411+
editor.unlockSelection();
412+
});
413+
408414
});
409415

410416
CKEDITOR.on( 'instanceReady', function( evt ) {

0 commit comments

Comments
 (0)