JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2.1
[ckeditor.git] / _source / plugins / selection / plugin.js
index 85981fa..9a85a84 100644 (file)
@@ -72,6 +72,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        var selectAllCmd =\r
        {\r
+               modes : { wysiwyg : 1, source : 1 },\r
                exec : function( editor )\r
                {\r
                        switch ( editor.mode )\r
@@ -80,7 +81,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        editor.document.$.execCommand( 'SelectAll', false, null );\r
                                        break;\r
                                case 'source' :\r
-                                       // TODO\r
+                                       // Select the contents of the textarea\r
+                                       var textarea = editor.textarea.$ ;\r
+                                       if ( CKEDITOR.env.ie )\r
+                                       {\r
+                                               textarea.createTextRange().execCommand( 'SelectAll' ) ;\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               textarea.selectionStart = 0 ;\r
+                                               textarea.selectionEnd = textarea.value.length ;\r
+                                       }\r
+                                       textarea.focus() ;\r
                        }\r
                },\r
                canUndo : false\r
@@ -108,8 +120,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                // "onfocusin" is fired before "onfocus". It makes it\r
                                                // possible to restore the selection before click\r
                                                // events get executed.\r
-                                               body.on( 'focusin', function()\r
+                                               body.on( 'focusin', function( evt )\r
                                                        {\r
+                                                               // If there are elements with layout they fire this event but\r
+                                                               // it must be ignored to allow edit its contents #4682\r
+                                                               if ( evt.data.$.srcElement.nodeName != 'BODY' )\r
+                                                                       return;\r
+\r
                                                                // If we have saved a range, restore it at this\r
                                                                // point.\r
                                                                if ( savedRange )\r
@@ -126,7 +143,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                }\r
                                                        });\r
 \r
-                                               editor.window.on( 'focus', function()\r
+                                               body.on( 'focus', function()\r
                                                        {\r
                                                                // Enable selections to be saved.\r
                                                                saveEnabled = true;\r
@@ -134,12 +151,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                saveSelection();\r
                                                        });\r
 \r
-                                               body.on( 'beforedeactivate', function()\r
+                                               body.on( 'beforedeactivate', function( evt )\r
                                                        {\r
+                                                               // Ignore this event if it's caused by focus switch between\r
+                                                               // internal editable control type elements, e.g. layouted paragraph. (#4682)\r
+                                                               if ( evt.data.$.toElement )\r
+                                                                       return;\r
+\r
                                                                // Disable selections from being saved.\r
                                                                saveEnabled = false;\r
                                                        });\r
 \r
+                                               // IE before version 8 will leave cursor blinking inside the document after\r
+                                               // editor blurred unless we clean up the selection. (#4716)\r
+                                               if ( CKEDITOR.env.ie && CKEDITOR.env.version < 8 )\r
+                                               {\r
+                                                       doc.getWindow().on( 'blur', function( evt )\r
+                                                       {\r
+                                                               editor.document.$.selection.empty();\r
+                                                       });\r
+                                               }\r
+\r
                                                // IE fires the "selectionchange" event when clicking\r
                                                // inside a selection. We don't want to capture that.\r
                                                body.on( 'mousedown', disableSave );\r
@@ -708,26 +740,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        if ( cache.selectedElement !== undefined )\r
                                return cache.selectedElement;\r
 \r
-                       var node;\r
-\r
-                       if ( this.getType() == CKEDITOR.SELECTION_ELEMENT )\r
-                       {\r
-                               var sel = this.getNative();\r
+                       var self = this;\r
 \r
-                               if ( CKEDITOR.env.ie )\r
+                       var node = CKEDITOR.tools.tryThese(\r
+                               // Is it native IE control type selection?\r
+                               function()\r
                                {\r
-                                       try\r
+                                       return self.getNative().createRange().item( 0 );\r
+                               },\r
+                               // Figure it out by checking if there's a single enclosed\r
+                               // node of the range.\r
+                               function()\r
+                               {\r
+                                       var range  = self.getRanges()[ 0 ];\r
+                                       range.shrink( CKEDITOR.SHRINK_ELEMENT );\r
+\r
+                                       var enclosed;\r
+                                       if ( range.startContainer.equals( range.endContainer )\r
+                                               && ( range.endOffset - range.startOffset ) == 1\r
+                                               && styleObjectElements[ ( enclosed = range.startContainer.getChild( range.startOffset ) ).getName() ] )\r
                                        {\r
-                                               node = sel.createRange().item(0);\r
+                                               return enclosed.$;\r
                                        }\r
-                                       catch(e) {}\r
-                               }\r
-                               else\r
-                               {\r
-                                       var range = sel.getRangeAt( 0 );\r
-                                       node = range.startContainer.childNodes[ range.startOffset ];\r
-                               }\r
-                       }\r
+                               });\r
 \r
                        return cache.selectedElement = ( node ? new CKEDITOR.dom.element( node ) : null );\r
                },\r
@@ -820,6 +855,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        range.moveToElementText( element.$ );\r
                                        range.select();\r
                                }\r
+                               finally\r
+                               {\r
+                                       this.document.fire( 'selectionchange' );\r
+                               }\r
 \r
                                this.reset();\r
                        }\r
@@ -1056,6 +1095,7 @@ CKEDITOR.dom.range.prototype.select =
                                else\r
                                        ieRange.select();\r
 \r
+                               this.moveToPosition( dummySpan, CKEDITOR.POSITION_BEFORE_START );\r
                                dummySpan.remove();\r
                        }\r
                        else\r
@@ -1064,6 +1104,8 @@ CKEDITOR.dom.range.prototype.select =
                                endNode.remove();\r
                                ieRange.select();\r
                        }\r
+\r
+                       this.document.fire( 'selectionchange' );\r
                }\r
        :\r
                function()\r