Ticket #3051: 3051_2.patch

File 3051_2.patch, 5.1 KB (added by Garry Yao, 15 years ago)
  • _source/core/dom/walker.js

     
    5353                        if ( node == this.endNode && !this.endInclusive )
    5454                                break;
    5555
    56                         if ( !this.evaluator && this.evaluator( node ) !== false )
     56                        if ( !this.evaluator || this.evaluator( node ) !== false )
    5757                                return node;
    5858                        else if ( breakOnFalse && this.evaluator )
    5959                                return false;
     
    6767
    6868        function iterateToLast( rtl )
    6969        {
    70                 var node, last;
     70                var node, last = null;
    7171
    7272                while ( node = iterate.call( this, rtl ) )
    7373                        last = node;
  • _source/core/dom/range.js

     
    10841084                                case CKEDITOR.ENLARGE_BLOCK_CONTENTS:
    10851085                                case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS:
    10861086                                        // DFS backward to get the block/list item boundary at or before the start.
    1087 
    1088                                         // Get the boundaries nodes.
    1089                                         var startNode = this.getTouchedStartNode(),
    1090                                                 endNode = this.getTouchedEndNode();
    1091 
    1092                                         if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.isBlockBoundary() )
     1087                                        // Get the outter boundaries nodes.
     1088                                        var startNode, endNode;
     1089                                       
     1090                                        // Use bookmark nodes to mock boundary nodes for collapsed
     1091                                        // range.
     1092                                        if( this.collapsed )
    10931093                                        {
    1094                                                 this.setStartAt( startNode,
    1095                                                         CKEDITOR.dtd.$empty[ startNode.getName() ] ?
    1096                                                                 CKEDITOR.POSITION_AFTER_END :
    1097                                                                 CKEDITOR.POSITION_AFTER_START );
     1094                                                var bm = this.createBookmark();
     1095                                                startNode= bm.startNode;
     1096                                                endNode = startNode;
    10981097                                        }
    10991098                                        else
    11001099                                        {
    1101                                                 // Get the function used to check the enlaarging limits.
    1102                                                 var guardFunction = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ?
    1103                                                                 CKEDITOR.dom.domWalker.blockBoundary() :
    1104                                                                 CKEDITOR.dom.domWalker.listItemBoundary() );
    1105 
    1106                                                 // Create the DOM walker, which will traverse the DOM.
    1107                                                 var walker = new CKEDITOR.dom.domWalker( startNode );
     1100                                                var boundaries = this.getBoundaryNodes(),
     1101                                                        startNode = boundaries.startNode,
     1102                                                        endNode = boundaries.endNode;
     1103                                        }
    11081104
    1109                                                 // Go walk in reverse sense.
    1110                                                 var data = walker.reverse( guardFunction );
    1111 
    1112                                                 var boundaryEvent = data.events.shift();
     1105                                        // function used to check the enlarging limits.
     1106                                        function checkOnBoundary( toNode, fromNode, customNodeNames )
     1107                                        {
     1108                                                // Check the enlarged node.
     1109                                                if( toNode && toNode.type == CKEDITOR.NODE_ELEMENT
     1110                                                        && toNode.isBlockBoundary(
     1111                                                                unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS? { br : 1 } : null ) )   
     1112                                                        return true;
    11131113
    1114                                                 this.setStartBefore( boundaryEvent.from );
     1114                                                // Check the current node.
     1115                                                else if( currentNode.type == CKEDITOR.NODE_ELEMENT &&
     1116                                                                        currentNode.isBlockBoundary(
     1117                                                                        unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS? { br : 1 } : null )
     1118                                                                        && ( enlargedNode.$ == currentNode.$.parentNode
     1119                                                                                        || enlargedNode.$ == currentNode.$.previousSibling ) )
     1120                                                        return true;
    11151121                                        }
    1116 
    1117                                         if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.isBlockBoundary() )
     1122                                       
     1123                                        // Enlarging the start boundary.
     1124                                        var walker = new CKEDITOR.dom.walker( startNode ),
     1125                                                enlargedNode = startNode,
     1126                                                currentNode = enlargedNode;
     1127                                        while( enlargedNode )
    11181128                                        {
    1119                                                 this.setEndAt( endNode,
    1120                                                         CKEDITOR.dtd.$empty[ endNode.getName() ] ?
    1121                                                                 CKEDITOR.POSITION_BEFORE_START :
    1122                                                                 CKEDITOR.POSITION_BEFORE_END );
     1129                                                // Check for those opening element.
     1130                                                if( !currentNode.getPrevious() &&
     1131                                                        checkOnBoundary( currentNode.getParent(), currentNode ) )
     1132                                                        break;
     1133                                                enlargedNode = walker.previous();
     1134                                                if( checkOnBoundary( enlargedNode, currentNode ) )
     1135                                                        break;
     1136                                                currentNode = enlargedNode;
    11231137                                        }
    1124                                         else
     1138                                        this.setStartAt( enlargedNode, CKEDITOR.POSITION_AFTER_END );
     1139                                       
     1140                                        // Enlarging the end boundary.
     1141                                        walker = new CKEDITOR.dom.walker( endNode ),
     1142                                                enlargedNode = endNode,
     1143                                                currentNode = enlargedNode;
     1144                                        while( enlargedNode )
    11251145                                        {
    1126                                                 // DFS forward to get the block/list item boundary at or before the end.
    1127                                                 walker.setNode( endNode );
    1128                                                 data = walker.forward( guardFunction );
    1129                                                 boundaryEvent = data.events.shift();
    1130 
    1131                                                 this.setEndAfter( boundaryEvent.from );
     1146                                                // Check for those closing element.
     1147                                                if( !currentNode.getNext() &&
     1148                                                        checkOnBoundary( currentNode.getParent(), currentNode ) )
     1149                                                        break;
     1150                                                enlargedNode = walker.next();
     1151                                                if( checkOnBoundary( enlargedNode, currentNode ) )
     1152                                                        break;
     1153                                                currentNode = enlargedNode;
     1154                                        }
     1155                                        this.setEndAt( enlargedNode, CKEDITOR.POSITION_BEFORE_START );
     1156                                       
     1157                                        if( bm )
     1158                                        {
     1159                                                // Backup current range.
     1160                                                var enlargedBm = this.createBookmark();
     1161                                               
     1162                                                // Destroy the marker bookmark.
     1163                                                this.moveToBookmark( bm );
     1164                                                this.moveToBookmark( enlargedBm );
    11321165                                        }
    11331166                        }
    11341167                },
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy