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