X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Frange.js;h=0146f6a6d691f222153f1d44ccf8ea907c3520d1;hp=3d8b10f0f31a50b2ff1c9af69466f228d25358aa;hb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;hpb=055b6b0792ce7dc53d47af606b367c04b927c2ab diff --git a/_source/core/dom/range.js b/_source/core/dom/range.js index 3d8b10f..0146f6a 100644 --- a/_source/core/dom/range.js +++ b/_source/core/dom/range.js @@ -397,6 +397,7 @@ CKEDITOR.dom.range = function( document ) var startNode, endNode; var baseId; var clone; + var collapsed = this.collapsed; startNode = this.document.createElement( 'span' ); startNode.setAttribute( '_fck_bookmark', 1 ); @@ -413,7 +414,7 @@ CKEDITOR.dom.range = function( document ) } // If collapsed, the endNode will not be created. - if ( !this.collapsed ) + if ( !collapsed ) { endNode = startNode.clone(); endNode.setHtml( ' ' ); @@ -442,7 +443,8 @@ CKEDITOR.dom.range = function( document ) return { startNode : serializable ? baseId + 'S' : startNode, endNode : serializable ? baseId + 'E' : endNode, - serializable : serializable + serializable : serializable, + collapsed : collapsed }; }, @@ -465,6 +467,8 @@ CKEDITOR.dom.range = function( document ) var startOffset = this.startOffset, endOffset = this.endOffset; + var collapsed = this.collapsed; + var child, previous; // If there is no range then get out of here. @@ -501,7 +505,7 @@ CKEDITOR.dom.range = function( document ) } // Process the end only if not normalized. - if ( !this.isCollapsed ) + if ( !collapsed ) { // Find out if the start is pointing to a text node that // will be normalized. @@ -532,10 +536,11 @@ CKEDITOR.dom.range = function( document ) return { start : startContainer.getAddress( normalized ), - end : this.isCollapsed ? null : endContainer.getAddress( normalized ), + end : collapsed ? null : endContainer.getAddress( normalized ), startOffset : startOffset, endOffset : endOffset, normalized : normalized, + collapsed : collapsed, is2 : true // It's a createBookmark2 bookmark. }; }, @@ -1632,24 +1637,34 @@ CKEDITOR.dom.range = function( document ) }, /** - * Check whether current range is on the inner edge of the specified element. - * @param {Number} checkType ( CKEDITOR.START | CKEDITOR.END ) The checking side. + * Check whether a range boundary is at the inner boundary of a given + * element. * @param {CKEDITOR.dom.element} element The target element to check. + * @param {Number} checkType The boundary to check for both the range + * and the element. It can be CKEDITOR.START or CKEDITOR.END. + * @returns {Boolean} "true" if the range boundary is at the inner + * boundary of the element. */ checkBoundaryOfElement : function( element, checkType ) { + var checkStart = ( checkType == CKEDITOR.START ); + + // Create a copy of this range, so we can manipulate it for our checks. var walkerRange = this.clone(); + + // Collapse the range at the proper size. + walkerRange.collapse( checkStart ); + // Expand the range to element boundary. - walkerRange[ checkType == CKEDITOR.START ? - 'setStartAt' : 'setEndAt' ] - ( element, checkType == CKEDITOR.START ? - CKEDITOR.POSITION_AFTER_START - : CKEDITOR.POSITION_BEFORE_END ); + walkerRange[ checkStart ? 'setStartAt' : 'setEndAt' ] + ( element, checkStart ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_BEFORE_END ); + // Create the walker, which will check if we have anything useful + // in the range. var walker = new CKEDITOR.dom.walker( walkerRange ); walker.evaluator = elementBoundaryEval; - return walker[ checkType == CKEDITOR.START ? - 'checkBackward' : 'checkForward' ](); + + return walker[ checkStart ? 'checkBackward' : 'checkForward' ](); }, // Calls to this function may produce changes to the DOM. The range may