JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / selection / plugin.js
index a42ef66..d8888c1 100644 (file)
@@ -78,6 +78,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        && node.getName() in CKEDITOR.dtd.$removeEmpty;\r
                }\r
 \r
+               function singletonBlock( node )\r
+               {\r
+                       var body = range.document.getBody();\r
+                       return !node.is( 'body' ) && body.getChildCount() == 1;\r
+               }\r
+\r
                var start = range.startContainer,\r
                        offset = range.startOffset;\r
 \r
@@ -86,7 +92,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                // 1. Empty inline element. <span>^</span>\r
                // 2. Adjoin to inline element. <p><strong>text</strong>^</p>\r
-               return !CKEDITOR.tools.trim( start.getHtml() ) ? isInlineCt( start ) : isInlineCt( start.getChild( offset - 1 ) ) || isInlineCt( start.getChild( offset ) );\r
+               // 3. The only empty block in document. <body><p>^</p></body> (#7222)\r
+               return !CKEDITOR.tools.trim( start.getHtml() ) ? isInlineCt( start ) || singletonBlock( start )\r
+                               : isInlineCt( start.getChild( offset - 1 ) ) || isInlineCt( start.getChild( offset ) );\r
        }\r
 \r
        var selectAllCmd =\r
@@ -469,6 +477,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                });\r
 \r
                        editor.selectionChange = checkSelectionChangeTimeout;\r
+\r
+                       // IE9 might cease to work if there's an object selection inside the iframe (#7639).\r
+                       CKEDITOR.env.ie9Compat && editor.on( 'destroy', function()\r
+                       {\r
+                               var sel = editor.getSelection();\r
+                               sel && sel.getNative().clear();\r
+                       }, null, null, 9 );\r
                }\r
        });\r
 \r
@@ -1138,12 +1153,35 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        return cache.selectedElement = ( node ? new CKEDITOR.dom.element( node ) : null );\r
                },\r
 \r
+               /**\r
+                * Retrieves the text contained within the range, empty string is returned for non-text selection.\r
+                * @returns {String} string of text within the current selection.\r
+                * @since 3.6.1\r
+                * @example\r
+                * var text = editor.getSelectedText();\r
+                * alert( text );\r
+                */\r
+               getSelectedText : function()\r
+               {\r
+                       var cache = this._.cache;\r
+                       if ( cache.selectedText !== undefined )\r
+                               return cache.selectedText;\r
+\r
+                       var text = '',\r
+                               nativeSel = this.getNative();\r
+                       if ( this.getType() == CKEDITOR.SELECTION_TEXT )\r
+                               text = CKEDITOR.env.ie ? nativeSel.createRange().text : nativeSel.toString();\r
+\r
+                       return ( cache.selectedText = text );\r
+               },\r
+\r
                lock : function()\r
                {\r
                        // Call all cacheable function.\r
                        this.getRanges();\r
                        this.getStartElement();\r
                        this.getSelectedElement();\r
+                       this.getSelectedText();\r
 \r
                        // The native selection is not available when locked.\r
                        this._.cache.nativeSel = {};\r