X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Frange.js;h=c8312b749b3008e1b304afd3e45c587104c06880;hp=30a78c4b31e83ba1b70deab99fa633533ec8f1ee;hb=6e682412d5cc0dfaedb376482e585bf2989c6863;hpb=2f22c0c38f17e75be5541089076885442aaa2377 diff --git a/_source/core/dom/range.js b/_source/core/dom/range.js index 30a78c4..c8312b7 100644 --- a/_source/core/dom/range.js +++ b/_source/core/dom/range.js @@ -349,7 +349,10 @@ CKEDITOR.dom.range = function( document ) // check(Start|End)OfBlock. function getCheckStartEndBlockEvalFunction( isStart ) { - var hadBr = false, bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true ); + var skipBogus = false, + bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true ), + nbspRegExp = /^[\t\r\n ]*(?: |\xa0)$/; + return function( node ) { // First ignore bookmark nodes. @@ -358,8 +361,16 @@ CKEDITOR.dom.range = function( document ) if ( node.type == CKEDITOR.NODE_TEXT ) { + // Skip the block filler NBSP. + if ( CKEDITOR.env.ie && + nbspRegExp.test( node.getText() ) && + !skipBogus && + !( isStart && node.getNext() ) ) + { + skipBogus = true; + } // If there's any visible text, then we're not at the start. - if ( node.hasAscendant( 'pre' ) || CKEDITOR.tools.trim( node.getText() ).length ) + else if ( node.hasAscendant( 'pre' ) || CKEDITOR.tools.trim( node.getText() ).length ) return false; } else if ( node.type == CKEDITOR.NODE_ELEMENT ) @@ -368,10 +379,14 @@ CKEDITOR.dom.range = function( document ) // at the start. if ( !inlineChildReqElements[ node.getName() ] ) { - // If we're working at the end-of-block, forgive the first
in non-IE - // browsers. - if ( !isStart && !CKEDITOR.env.ie && node.getName() == 'br' && !hadBr ) - hadBr = true; + // Skip the padding block br. + if ( !CKEDITOR.env.ie && + node.is( 'br' ) && + !skipBogus && + !( isStart && node.getNext() ) ) + { + skipBogus = true; + } else return false; } @@ -513,7 +528,7 @@ CKEDITOR.dom.range = function( document ) if ( serializable ) { baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber(); - startNode.setAttribute( 'id', baseId + 'S' ); + startNode.setAttribute( 'id', baseId + ( collapsed ? 'C' : 'S' ) ); } // If collapsed, the endNode will not be created. @@ -544,7 +559,7 @@ CKEDITOR.dom.range = function( document ) this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END ); return { - startNode : serializable ? baseId + 'S' : startNode, + startNode : serializable ? baseId + ( collapsed ? 'C' : 'S' ) : startNode, endNode : serializable ? baseId + 'E' : endNode, serializable : serializable, collapsed : collapsed @@ -1828,11 +1843,6 @@ CKEDITOR.dom.range = function( document ) return false; } - // Antecipate the trim() call here, so the walker will not make - // changes to the DOM, which would not get reflected into this - // range otherwise. - this.trim(); - // We need to grab the block element holding the start boundary, so // let's use an element path for it. var path = new CKEDITOR.dom.elementPath( this.startContainer ); @@ -1862,11 +1872,6 @@ CKEDITOR.dom.range = function( document ) return false; } - // Antecipate the trim() call here, so the walker will not make - // changes to the DOM, which would not get reflected into this - // range otherwise. - this.trim(); - // We need to grab the block element holding the start boundary, so // let's use an element path for it. var path = new CKEDITOR.dom.elementPath( this.endContainer ); @@ -1934,16 +1939,14 @@ CKEDITOR.dom.range = function( document ) */ moveToElementEditablePosition : function( el, isMoveToEnd ) { + var nbspRegExp = /^[\t\r\n ]*(?: |\xa0)$/; + function nextDFS( node, childOnly ) { var next; - if ( node.type == CKEDITOR.NODE_ELEMENT - && node.isEditable( false ) - && !CKEDITOR.dtd.$nonEditable[ node.getName() ] ) - { + if ( node.type == CKEDITOR.NODE_ELEMENT && node.isEditable( false ) ) next = node[ isMoveToEnd ? 'getLast' : 'getFirst' ]( nonWhitespaceOrBookmarkEval ); - } if ( !childOnly && !next ) next = node[ isMoveToEnd ? 'getPrevious' : 'getNext' ]( nonWhitespaceOrBookmarkEval ); @@ -1951,6 +1954,15 @@ CKEDITOR.dom.range = function( document ) return next; } + // Handle non-editable element e.g. HR. + if ( el.type == CKEDITOR.NODE_ELEMENT && !el.isEditable( false ) ) + { + this.moveToPosition( el, isMoveToEnd ? + CKEDITOR.POSITION_AFTER_END : + CKEDITOR.POSITION_BEFORE_START ); + return true; + } + var found = 0; while ( el ) @@ -1958,7 +1970,11 @@ CKEDITOR.dom.range = function( document ) // Stop immediately if we've found a text node. if ( el.type == CKEDITOR.NODE_TEXT ) { - this.moveToPosition( el, isMoveToEnd ? + // Put cursor before block filler. + if ( isMoveToEnd && this.checkEndOfBlock() && nbspRegExp.test( el.getText() ) ) + this.moveToPosition( el, CKEDITOR.POSITION_BEFORE_START ); + else + this.moveToPosition( el, isMoveToEnd ? CKEDITOR.POSITION_AFTER_END : CKEDITOR.POSITION_BEFORE_START ); found = 1; @@ -1975,6 +1991,9 @@ CKEDITOR.dom.range = function( document ) CKEDITOR.POSITION_AFTER_START ); found = 1; } + // Put cursor before padding block br. + else if ( isMoveToEnd && el.is( 'br' ) && this.checkEndOfBlock() ) + this.moveToPosition( el, CKEDITOR.POSITION_BEFORE_START ); } el = nextDFS( el, found );