JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / enterkey / plugin.js
index 10b7e62..4114516 100644 (file)
@@ -24,6 +24,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // Get the range for the current selection.\r
                        range = range || getRange( editor );\r
 \r
+                       // We may not have valid ranges to work on, like when inside a\r
+                       // contenteditable=false element.\r
+                       if ( !range )\r
+                               return;\r
+\r
                        var doc = range.document;\r
 \r
                        // Exit the list when we're inside an empty list item block. (#5376)\r
@@ -64,7 +69,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                if ( node.is( 'li' ) )\r
                                {\r
                                        nextBlock.breakParent( node );\r
-                                       nextBlock.move( nextBlock.getNext(), true );\r
+                                       nextBlock.move( nextBlock.getNext(), 1 );\r
                                }\r
                        }\r
                        else if ( previousBlock && ( node = previousBlock.getParent() ) && node.is( 'li' ) )\r
@@ -93,7 +98,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        }\r
                        else\r
                        {\r
-                               var newBlock;\r
+                               var newBlock,\r
+                                       newBlockDir;\r
 \r
                                if ( previousBlock )\r
                                {\r
@@ -110,7 +116,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        newBlock = nextBlock.clone();\r
 \r
                                if ( !newBlock )\r
+                               {\r
                                        newBlock = doc.createElement( blockTag );\r
+                                       if ( previousBlock && ( newBlockDir = previousBlock.getDirection() ) )\r
+                                               newBlock.setAttribute( 'dir', newBlockDir );\r
+                               }\r
                                // Force the enter block unless we're talking of a list item.\r
                                else if ( forceMode && !newBlock.is( 'li' ) )\r
                                        newBlock.renameNode( blockTag );\r
@@ -189,6 +199,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // Get the range for the current selection.\r
                        range = range || getRange( editor );\r
 \r
+                       // We may not have valid ranges to work on, like when inside a\r
+                       // contenteditable=false element.\r
+                       if ( !range )\r
+                               return;\r
+\r
                        var doc = range.document;\r
 \r
                        // Determine the block element to be used.\r
@@ -212,15 +227,28 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // If we are at the end of a header block.\r
                        if ( !forceMode && isEndOfBlock && headerTagRegex.test( startBlockTag ) )\r
                        {\r
-                               // Insert a <br> after the current paragraph.\r
-                               doc.createElement( 'br' ).insertAfter( startBlock );\r
+                               var newBlock,\r
+                                       newBlockDir;\r
 \r
-                               // A text node is required by Gecko only to make the cursor blink.\r
-                               if ( CKEDITOR.env.gecko )\r
-                                       doc.createText( '' ).insertAfter( startBlock );\r
+                               if ( newBlockDir = startBlock.getDirection() )\r
+                               {\r
+                                       newBlock = doc.createElement( 'div' );\r
+                                       newBlock.setAttribute( 'dir', newBlockDir );\r
+                                       newBlock.insertAfter( startBlock );\r
+                                       range.setStart( newBlock, 0 );\r
+                               }\r
+                               else\r
+                               {\r
+                                       // Insert a <br> after the current paragraph.\r
+                                       doc.createElement( 'br' ).insertAfter( startBlock );\r
+\r
+                                       // A text node is required by Gecko only to make the cursor blink.\r
+                                       if ( CKEDITOR.env.gecko )\r
+                                               doc.createText( '' ).insertAfter( startBlock );\r
 \r
-                               // IE has different behaviors regarding position.\r
-                               range.setStartAt( startBlock.getNext(), CKEDITOR.env.ie ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_START );\r
+                                       // IE has different behaviors regarding position.\r
+                                       range.setStartAt( startBlock.getNext(), CKEDITOR.env.ie ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_START );\r
+                               }\r
                        }\r
                        else\r
                        {\r
@@ -307,7 +335,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        return true;\r
                }\r
                else\r
-                       return enter( editor, editor.config.shiftEnterMode, true );\r
+                       return enter( editor, editor.config.shiftEnterMode, 1 );\r
        }\r
 \r
        function enter( editor, mode, forceMode )\r
@@ -325,7 +353,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                setTimeout( function()\r
                        {\r
                                editor.fire( 'saveSnapshot' );  // Save undo step.\r
-                               if ( mode == CKEDITOR.ENTER_BR || editor.getSelection().getStartElement().hasAscendant( 'pre', true ) )\r
+                               if ( mode == CKEDITOR.ENTER_BR || editor.getSelection().getStartElement().hasAscendant( 'pre', 1 ) )\r
                                        enterBr( editor, mode, null, forceMode );\r
                                else\r
                                        enterBlock( editor, mode, null, forceMode );\r
@@ -339,7 +367,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        function getRange( editor )\r
        {\r
                // Get the selection ranges.\r
-               var ranges = editor.getSelection().getRanges();\r
+               var ranges = editor.getSelection().getRanges( true );\r
 \r
                // Delete the contents of all ranges except the first one.\r
                for ( var i = ranges.length - 1 ; i > 0 ; i-- )\r