JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / horizontalrule / plugin.js
index 80ae0dc..3eac319 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -11,9 +11,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 {\r
        var horizontalruleCmd =\r
        {\r
+               canUndo : false,    // The undo snapshot will be handled by 'insertElement'.\r
                exec : function( editor )\r
                {\r
-                       editor.insertElement( editor.document.createElement( 'hr' ) );\r
+                       var hr = editor.document.createElement( 'hr' ),\r
+                               range = new CKEDITOR.dom.range( editor.document );\r
+\r
+                       editor.insertElement( hr );\r
+\r
+                       // If there's nothing or a non-editable block followed by, establish a new paragraph\r
+                       // to make sure cursor is not trapped.\r
+                       range.moveToPosition( hr, CKEDITOR.POSITION_AFTER_END );\r
+                       var next = hr.getNext();\r
+                       if ( !next || next.type == CKEDITOR.NODE_ELEMENT && !next.isEditable() )\r
+                               range.fixBlock( true, editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );\r
+\r
+                       range.select();\r
                }\r
        };\r
 \r