});\r
}\r
\r
+ var scroll;\r
// IE fires the "selectionchange" event when clicking\r
// inside a selection. We don't want to capture that.\r
- body.on( 'mousedown', function ()\r
+ body.on( 'mousedown', function( evt )\r
{\r
+ // IE scrolls document to top on right mousedown\r
+ // when editor has no focus, remember this scroll\r
+ // position and revert it before context menu opens. (#5778)\r
+ if ( evt.data.$.button == 2 )\r
+ {\r
+ var sel = editor.document.$.selection;\r
+ if ( sel.type == 'None' )\r
+ scroll = editor.window.getScrollPosition();\r
+ }\r
disableSave();\r
});\r
\r
body.on( 'mouseup',\r
- function()\r
+ function( evt )\r
{\r
+ // Restore recorded scroll position when needed on right mouseup.\r
+ if ( evt.data.$.button == 2 && scroll )\r
+ {\r
+ editor.document.$.documentElement.scrollLeft = scroll.x;\r
+ editor.document.$.documentElement.scrollTop = scroll.y;\r
+ }\r
+ scroll = null;\r
+\r
saveEnabled = true;\r
setTimeout( function()\r
{\r
// tranform the native ranges in CKEDITOR.dom.range\r
// instances.\r
\r
- var ranges = [];\r
- var sel = this.getNative();\r
+ var ranges = [],\r
+ range,\r
+ doc = this.document,\r
+ sel = this.getNative();\r
\r
if ( !sel )\r
- return [];\r
+ return ranges;\r
+\r
+ // On WebKit, it may happen that we'll have no selection\r
+ // available. We normalize it here by replicating the\r
+ // behavior of other browsers.\r
+ if ( !sel.rangeCount )\r
+ {\r
+ range = new CKEDITOR.dom.range( doc );\r
+ range.moveToElementEditStart( doc.getBody() );\r
+ ranges.push( range );\r
+ }\r
\r
for ( var i = 0 ; i < sel.rangeCount ; i++ )\r
{\r
var nativeRange = sel.getRangeAt( i );\r
- var range = new CKEDITOR.dom.range( this.document );\r
+\r
+ range = new CKEDITOR.dom.range( doc );\r
\r
range.setStart( new CKEDITOR.dom.node( nativeRange.startContainer ), nativeRange.startOffset );\r
range.setEnd( new CKEDITOR.dom.node( nativeRange.endContainer ), nativeRange.endOffset );\r
// In FF2, if we have a collapsed range, inside an empty\r
// element, we must add something to it otherwise the caret\r
// will not be visible.\r
+ // In Opera instead, the selection will be moved out of the\r
+ // element. (#4657)\r
if ( range.collapsed &&\r
- ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) &&\r
+ ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) ) &&\r
startContainer.type == CKEDITOR.NODE_ELEMENT &&\r
!startContainer.getChildCount() )\r
{\r