X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fselection%2Fplugin.js;h=17e2c52eeff55d92fa90f8a731ed0ce859c4c712;hp=f0d2c4456ffa10d94a892dc55aea9f01df9d69ac;hb=039a051ccf3901311661022a30afd60fc38130c9;hpb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7 diff --git a/_source/plugins/selection/plugin.js b/_source/plugins/selection/plugin.js index f0d2c44..17e2c52 100644 --- a/_source/plugins/selection/plugin.js +++ b/_source/plugins/selection/plugin.js @@ -133,7 +133,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // point. if ( savedRange ) { - if ( restoreEnabled ) + // Range restored here might invalidate the DOM structure thus break up + // the locked selection, give it up. (#6083) + var lockedSelection = doc.getCustomData( 'cke_locked_selection' ); + if ( restoreEnabled && !lockedSelection ) { // Well not break because of this. try @@ -151,7 +154,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license body.on( 'focus', function() { // Enable selections to be saved. - saveEnabled = true; + saveEnabled = 1; saveSelection(); }); @@ -164,7 +167,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return; // Disable selections from being saved. - saveEnabled = false; + saveEnabled = 0; restoreEnabled = 1; }); @@ -174,13 +177,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { editor.on( 'blur', function( evt ) { - editor.document && editor.document.$.selection.empty(); + // Try/Catch to avoid errors if the editor is hidden. (#6375) + try + { + editor.document && editor.document.$.selection.empty(); + } + catch (e) {} }); } // Listening on document element ensures that // scrollbar is included. (#5280) - html.on( 'mousedown', function () + html.on( 'mousedown', function() { // Lock restore selection now, as we have // a followed 'click' event which introduce @@ -188,7 +196,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license restoreEnabled = 0; }); - html.on( 'mouseup', function () + html.on( 'mouseup', function() { restoreEnabled = 1; }); @@ -235,7 +243,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } scroll = null; - saveEnabled = true; + saveEnabled = 1; setTimeout( function() { saveSelection( true ); @@ -247,7 +255,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license body.on( 'keyup', function() { - saveEnabled = true; + saveEnabled = 1; saveSelection(); }); @@ -258,7 +266,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function disableSave() { - saveEnabled = false; + saveEnabled = 0; } function saveSelection( testIt ) @@ -400,7 +408,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return lockedSelection; this.document = document; - this.isLocked = false; + this.isLocked = 0; this._ = { cache : {} @@ -543,7 +551,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * var ranges = selection.getRanges(); * alert(ranges.length); */ - getRanges : (function () + getRanges : (function() { var func = CKEDITOR.env.ie ? ( function() @@ -655,6 +663,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license boundaryInfo = getBoundaryInformation( nativeRange ); range.setEnd( new CKEDITOR.dom.node( boundaryInfo.container ), boundaryInfo.offset ); + // Correct an invalid IE range case on empty list item. (#5850) + if ( range.endContainer.getPosition( range.startContainer ) & CKEDITOR.POSITION_PRECEDING + && range.endOffset <= range.startContainer.getIndex() ) + { + range.collapse(); + } + return [ range ]; } else if ( type == CKEDITOR.SELECTION_ELEMENT ) @@ -740,7 +755,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Drop range spans inside one ready-only node. var parent = range.getCommonAncestor(); - if ( parent.isReadOnly()) + if ( parent.isReadOnly() ) ranges.splice( i, 1 ); if ( range.collapsed ) @@ -850,7 +865,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Decrease the range content to exclude particial // selected node on the start which doesn't have // visual impact. ( #3231 ) - while ( true ) + while ( 1 ) { var startContainer = range.startContainer, startOffset = range.startOffset; @@ -870,32 +885,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license node = node.getChild( range.startOffset ); if ( !node || node.type != CKEDITOR.NODE_ELEMENT ) - return range.startContainer; - - var child = node.getFirst(); - while ( child && child.type == CKEDITOR.NODE_ELEMENT ) + node = range.startContainer; + else { - node = child; - child = child.getFirst(); + var child = node.getFirst(); + while ( child && child.type == CKEDITOR.NODE_ELEMENT ) + { + node = child; + child = child.getFirst(); + } } - - return node; } - } - - if ( CKEDITOR.env.ie ) - { - range = sel.createRange(); - range.collapse( true ); - - node = range.parentElement(); - } - else - { - node = sel.anchorNode; + else + { + node = range.startContainer; + if ( node.type != CKEDITOR.NODE_ELEMENT ) + node = node.getParent(); + } - if ( node && node.nodeType != 1 ) - node = node.parentNode; + node = node.$; } } @@ -959,7 +967,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // The native selection is not available when locked. this._.cache.nativeSel = {}; - this.isLocked = true; + this.isLocked = 1; // Save this selection inside the DOM document. this.document.setCustomData( 'cke_locked_selection', this ); @@ -979,7 +987,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var selectedElement = lockedSelection.getSelectedElement(), ranges = !selectedElement && lockedSelection.getRanges(); - this.isLocked = false; + this.isLocked = 0; this.reset(); doc.getBody().focus(); @@ -993,7 +1001,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !lockedSelection || !restore ) { - this.isLocked = false; + this.isLocked = 0; this.reset(); } }, @@ -1034,7 +1042,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license range.addElement( element.$ ); range.select(); } - catch(e) + catch( e ) { // If failed, select it as a text range. range = this.document.$.body.createTextRange();