+ // Prevent backspace from navigating off the page.\r
+ keystrokeHandler.blockedKeystrokes[ 8 ] = !editable;\r
+ keystrokeHandler.attach( domDocument );\r
+\r
+ domDocument.getDocumentElement().addClass( domDocument.$.compatMode );\r
+ // Override keystroke behaviors.\r
+ editable && domDocument.on( 'keydown', function( evt )\r
+ {\r
+ var keyCode = evt.data.getKeystroke();\r
+\r
+ // Backspace OR Delete.\r
+ if ( keyCode in { 8 : 1, 46 : 1 } )\r
+ {\r
+ var sel = editor.getSelection(),\r
+ selected = sel.getSelectedElement(),\r
+ range = sel.getRanges()[ 0 ],\r
+ path = new CKEDITOR.dom.elementPath( range.startContainer ),\r
+ block,\r
+ parent,\r
+ next,\r
+ rtl = keyCode == 8;\r
+\r
+ // Override keystrokes which should have deletion behavior\r
+ // on fully selected element . (#4047) (#7645)\r
+ if ( selected )\r
+ {\r
+ // Make undo snapshot.\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ // Delete any element that 'hasLayout' (e.g. hr,table) in IE8 will\r
+ // break up the selection, safely manage it here. (#4795)\r
+ range.moveToPosition( selected, CKEDITOR.POSITION_BEFORE_START );\r
+ // Remove the control manually.\r
+ selected.remove();\r
+ range.select();\r
+\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ evt.data.preventDefault();\r
+ }\r
+ else\r
+ {\r
+ // Handle the following special cases: (#6217)\r
+ // 1. Del/Backspace key before/after table;\r
+ // 2. Backspace Key after start of table.\r
+ if ( ( block = path.block ) &&\r
+ range[ rtl ? 'checkStartOfBlock' : 'checkEndOfBlock' ]() &&\r
+ ( next = block[ rtl ? 'getPrevious' : 'getNext' ]( notWhitespaceEval ) ) &&\r
+ next.is( 'table' ) )\r
+ {\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ // Remove the current empty block.\r
+ if ( range[ rtl ? 'checkEndOfBlock' : 'checkStartOfBlock' ]() )\r
+ block.remove();\r
+\r
+ // Move cursor to the beginning/end of table cell.\r
+ range[ 'moveToElementEdit' + ( rtl ? 'End' : 'Start' ) ]( next );\r
+ range.select();\r
+\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ evt.data.preventDefault();\r
+ }\r
+ else if ( path.blockLimit.is( 'td' ) &&\r
+ ( parent = path.blockLimit.getAscendant( 'table' ) ) &&\r
+ range.checkBoundaryOfElement( parent, rtl ? CKEDITOR.START : CKEDITOR.END ) &&\r
+ ( next = parent[ rtl ? 'getPrevious' : 'getNext' ]( notWhitespaceEval ) ) )\r
+ {\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ // Move cursor to the end of previous block.\r
+ range[ 'moveToElementEdit' + ( rtl ? 'End' : 'Start' ) ]( next );\r
+\r
+ // Remove any previous empty block.\r
+ if ( range.checkStartOfBlock() && range.checkEndOfBlock() )\r
+ next.remove();\r
+ else\r
+ range.select();\r
+\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ evt.data.preventDefault();\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ // PageUp OR PageDown\r
+ if ( keyCode == 33 || keyCode == 34 )\r
+ {\r
+ if ( CKEDITOR.env.gecko )\r
+ {\r
+ var body = domDocument.getBody();\r
+\r
+ // Page up/down cause editor selection to leak\r
+ // outside of editable thus we try to intercept\r
+ // the behavior, while it affects only happen\r
+ // when editor contents are not overflowed. (#7955)\r
+ if ( domWindow.$.innerHeight > body.$.offsetHeight )\r
+ {\r
+ range = new CKEDITOR.dom.range( domDocument );\r
+ range[ keyCode == 33 ? 'moveToElementEditStart' : 'moveToElementEditEnd']( body );\r
+ range.select();\r
+ evt.data.preventDefault();\r
+ }\r
+ }\r
+\r
+ }\r
+ } );\r
+\r
+ // PageUp/PageDown scrolling is broken in document\r
+ // with standard doctype, manually fix it. (#4736)\r
+ if ( CKEDITOR.env.ie && domDocument.$.compatMode == 'CSS1Compat' )\r
+ {\r
+ var pageUpDownKeys = { 33 : 1, 34 : 1 };\r
+ domDocument.on( 'keydown', function( evt )\r
+ {\r
+ if ( evt.data.getKeystroke() in pageUpDownKeys )\r
+ {\r
+ setTimeout( function ()\r
+ {\r
+ editor.getSelection().scrollIntoView();\r
+ }, 0 );\r
+ }\r
+ } );\r
+ }\r
+\r
+ // Prevent IE from leaving new paragraph after deleting all contents in body. (#6966)\r
+ if ( CKEDITOR.env.ie && editor.config.enterMode != CKEDITOR.ENTER_P )\r
+ {\r
+ domDocument.on( 'selectionchange', function()\r
+ {\r
+ var body = domDocument.getBody(),\r
+ sel = editor.getSelection(),\r
+ range = sel && sel.getRanges()[ 0 ];\r
+\r
+ if ( range && body.getHtml().match( /^<p> <\/p>$/i )\r
+ && range.startContainer.equals( body ) )\r
+ {\r
+ // Avoid the ambiguity from a real user cursor position.\r
+ setTimeout( function ()\r
+ {\r
+ range = editor.getSelection().getRanges()[ 0 ];\r
+ if ( !range.startContainer.equals ( 'body' ) )\r
+ {\r
+ body.getFirst().remove( 1 );\r
+ range.moveToElementEditEnd( body );\r
+ range.select( 1 );\r
+ }\r
+ }, 0 );\r
+ }\r
+ });\r
+ }\r