Skip to content

Commit

Permalink
Merge branch 't/9521'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Nov 7, 2012
2 parents bf84cd5 + 57049a1 commit ddd2fb6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
64 changes: 28 additions & 36 deletions core/editable.js
Expand Up @@ -155,6 +155,7 @@
* @see CKEDITOR.editor#insertHtml
*/
insertHtml: function( data, mode ) {
beforeInsert( this );
// Default mode is 'html'.
insert( this, mode == 'text' ? 'text' : 'html', data );
},
Expand All @@ -163,6 +164,8 @@
* @see CKEDITOR.editor#insertText
*/
insertText: function( text ) {
beforeInsert( this );

var editor = this.editor,
mode = editor.getSelection().getStartElement().hasAscendant( 'pre', true ) ? CKEDITOR.ENTER_BR : editor.config.enterMode,
isEnterBrMode = mode == CKEDITOR.ENTER_BR,
Expand Down Expand Up @@ -211,10 +214,7 @@
* @see CKEDITOR.editor#insertElement
*/
insertElement: function( element ) {
// TODO this should be gone after refactoring insertElement.
// TODO: For unknown reason we must call directly on the editable to put the focus immediately.
this.editor.focus();
this.editor.fire( 'saveSnapshot' );
beforeInsert( this );

var editor = this.editor,
enterMode = editor.config.enterMode,
Expand Down Expand Up @@ -294,14 +294,8 @@

selection.selectRanges( [ range ] );

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

/**
Expand Down Expand Up @@ -931,8 +925,6 @@
// Inserts the given (valid) HTML into the range position (with range content deleted),
// guarantee it's result to be a valid DOM tree.
function insert( editable, type, data ) {
beforeInsert( editable );

var editor = editable.editor,
doc = editable.getDocument(),
selection = editor.getSelection(),
Expand Down Expand Up @@ -993,13 +985,6 @@
afterInsert( editable );
}

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' );
}

// Prepare range to its data deletion.
// Delete its contents.
// Prepare it to insertion.
Expand Down Expand Up @@ -1319,21 +1304,6 @@

}

function afterInsert( editable ) {
var editor = editable.editor;

// Scroll using selection, not ranges, to affect native pastes.
editor.getSelection().scrollIntoView();

// Save snaps after the whole execution completed.
// This's a workaround for make DOM modification's happened after
// 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
// call.
setTimeout( function() {
editor.fire( 'saveSnapshot' );
}, 0 );
}

//
// HELPERS ------------------------------------------------------------
//
Expand Down Expand Up @@ -1611,6 +1581,28 @@
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, noScroll ) {
var editor = editable.editor;

// Scroll using selection, not ranges, to affect native pastes.
!noScroll && editor.getSelection().scrollIntoView();

// Save snaps after the whole execution completed.
// This's a workaround for make DOM modification's happened after
// 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
// call.
setTimeout( function() {
editor.fire( 'saveSnapshot' );
}, 0 );
}

})();

/**
Expand Down
6 changes: 6 additions & 0 deletions core/selection.js
Expand Up @@ -405,6 +405,12 @@
CKEDITOR.env.ie9Compat && editor.on( 'beforeDestroy', clearSelection, null, null, 9 );
// Webkit's selection will mess up after the data loading.
CKEDITOR.env.webkit && editor.on( 'setData', clearSelection );

// Invalidate locked selection when unloading DOM (e.g. after setData). (#9521)
editor.on( 'contentDomUnload', function() {
editor.unlockSelection();
});

});

CKEDITOR.on( 'instanceReady', function( evt ) {
Expand Down

0 comments on commit ddd2fb6

Please sign in to comment.