@@ -233,8 +233,13 @@ CKEDITOR.dom.range = function( document ) {
233
233
// Creates the appropriate node evaluator for the dom walker used inside
234
234
// check(Start|End)OfBlock.
235
235
function getCheckStartEndBlockEvalFunction ( isStart ) {
236
- var hadBr = false ;
236
+ var hadBr = false ,
237
+ bookmarkEvaluator = CKEDITOR . dom . walker . bookmark ( true ) ;
237
238
return function ( node ) {
239
+ // First ignore bookmark nodes.
240
+ if ( bookmarkEvaluator ( node ) )
241
+ return true ;
242
+
238
243
if ( node . type == CKEDITOR . NODE_TEXT ) {
239
244
// If there's any visible text, then we're not at the start.
240
245
if ( CKEDITOR . tools . trim ( node . getText ( ) ) . length )
@@ -975,34 +980,62 @@ CKEDITOR.dom.range = function( document ) {
975
980
case CKEDITOR . ENLARGE_LIST_ITEM_CONTENTS :
976
981
977
982
// Enlarging the start boundary.
978
- var walkerRange = new CKEDITOR . dom . range ( this . document ) ;
979
- walkerRange . setStartAt ( this . document . getBody ( ) , CKEDITOR . POSITION_AFTER_START ) ;
983
+ var walkerRange = new CKEDITOR . dom . range ( this . document ) ,
984
+ body = this . document . getBody ( ) ;
985
+ walkerRange . setStartAt ( body , CKEDITOR . POSITION_AFTER_START ) ;
980
986
walkerRange . setEnd ( this . startContainer , this . startOffset ) ;
981
987
982
988
var walker = new CKEDITOR . dom . walker ( walkerRange ) ,
983
-
984
- guard = CKEDITOR . dom . walker . blockBoundary (
989
+ blockBoundary , // The node on which the enlarging should stop.
990
+ tailBr , //
991
+ defaultGuard = CKEDITOR . dom . walker . blockBoundary (
985
992
( unit == CKEDITOR . ENLARGE_LIST_ITEM_CONTENTS ) ? { br :1 } : null ) ,
986
- tailBr ,
987
- listGuard = function ( node ) {
988
- var result = guard ( node ) ;
989
- if ( ! result && node . is && node . is ( 'br' ) )
993
+ // Record the encountered 'blockBoundary' for later use.
994
+ boundaryGuard = function ( node ) {
995
+ var retval = defaultGuard ( node ) ;
996
+ if ( ! retval )
997
+ blockBoundary = node ;
998
+ return retval ;
999
+ } ,
1000
+ // Record the encounted 'tailBr' for later use.
1001
+ tailBrGuard = function ( node ) {
1002
+ var retval = boundaryGuard ( node ) ;
1003
+ if ( ! retval && node . is && node . is ( 'br' ) )
990
1004
tailBr = node ;
991
- return result ;
1005
+ return retval ;
992
1006
} ;
993
- walker . guard = guard ;
994
1007
995
- if ( ( enlargeable = walker . lastBackward ( ) ) )
996
- this . setStartAt ( enlargeable , CKEDITOR . POSITION_BEFORE_START ) ;
1008
+ walker . guard = boundaryGuard ;
1009
+
1010
+
1011
+ if ( ( enlargeable = walker . lastBackward ( ) ) ) {
1012
+ // It's the body which stop the enlaring if no block boundary found.
1013
+ blockBoundary = blockBoundary || body ;
1014
+
1015
+ // Start the range at different position by comparing
1016
+ // the document position of it with 'enlargeable' node.
1017
+ this . setStartAt ( blockBoundary , blockBoundary . contains ( enlargeable ) ? CKEDITOR . POSITION_AFTER_START : CKEDITOR . POSITION_AFTER_END ) ;
1018
+ }
997
1019
998
1020
// Enlarging the end boundary.
999
1021
walkerRange = this . clone ( ) ;
1000
1022
walkerRange . collapse ( ) ;
1001
- walkerRange . setEndAt ( this . document . getBody ( ) , CKEDITOR . POSITION_BEFORE_END ) ;
1023
+ walkerRange . setEndAt ( body , CKEDITOR . POSITION_BEFORE_END ) ;
1002
1024
walker = new CKEDITOR . dom . walker ( walkerRange ) ;
1003
- walker . guard = ( unit == CKEDITOR . ENLARGE_LIST_ITEM_CONTENTS ) ? listGuard : guard ;
1004
- if ( ( enlargeable = walker . lastForward ( ) ) )
1005
- this . setEndAfter ( enlargeable ) ;
1025
+
1026
+ // tailBrGuard only used for on range end.
1027
+ walker . guard = ( unit == CKEDITOR . ENLARGE_LIST_ITEM_CONTENTS ) ? tailBrGuard : boundaryGuard ;
1028
+ blockBoundary = null ;
1029
+ // End the range right before the block boundary node.
1030
+ ;
1031
+ if ( ( enlargeable = walker . lastForward ( ) ) ) {
1032
+ // It's the body which stop the enlaring if no block boundary found.
1033
+ blockBoundary = blockBoundary || body ;
1034
+
1035
+ // Start the range at different position by comparing
1036
+ // the document position of it with 'enlargeable' node.
1037
+ this . setEndAt ( blockBoundary , blockBoundary . contains ( enlargeable ) ? CKEDITOR . POSITION_BEFORE_END : CKEDITOR . POSITION_BEFORE_START ) ;
1038
+ }
1006
1039
// We must include the <br> at the end of range if there's
1007
1040
// one and we're expanding list item contents
1008
1041
if ( tailBr )
0 commit comments