Ticket #3304: 3304_6.patch

File 3304_6.patch, 23.8 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/find/dialogs/find.js

     
    55
    66(function()
    77{
    8         // Element tag names which prevent characters counting.
    9         var characterBoundaryElementsEnum =
     8        function guardDomWalkerNonEmptyTextNode( node )
    109        {
    11                 address :1, blockquote :1, dl :1, h1 :1, h2 :1, h3 :1,
    12                 h4 :1, h5 :1, h6 :1, p :1, pre :1, li :1, dt :1, de :1, div :1, td:1, th:1
    13         };
     10                return ( node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 )
     11        }
    1412
    15         var guardDomWalkerNonEmptyTextNode = function( evt )
     13        /**
     14         * Elements which break characters been considered as sequence.
     15        */
     16        function checkCharactersBoundary ( node )
    1617        {
    17                 if ( evt.data.to && evt.data.to.type == CKEDITOR.NODE_TEXT
    18                         && evt.data.to.$.length > 0 )
    19                         this.stop();
    20                 CKEDITOR.dom.domWalker.blockBoundary( { br : 1 } ).call( this, evt );
    21         };
    22 
     18                var dtd = CKEDITOR.dtd;
     19                return node.isBlockBoundary(
     20                        CKEDITOR.tools.extend( {}, dtd.$empty, dtd.$nonEditable ) );
     21        }
    2322
    2423        /**
    2524         * Get the cursor object which represent both current character and it's dom
     
    3029                var obj = {
    3130                        textNode : this.textNode,
    3231                        offset : this.offset,
    33                         character : this.textNode ? this.textNode.getText().charAt( this.offset ) : null,
     32                        character : this.textNode ?
     33                                this.textNode.getText().charAt( this.offset ) : null,
    3434                        hitMatchBoundary : this._.matchBoundary
    3535                };
    3636                return obj;
     
    7575                 * Iterator which walk through document char by char.
    7676                 * @param {Object} start
    7777                 * @param {Number} offset
     78                 * @param {Boolean} isStrict
    7879                 */
    79                 var characterWalker = function( start, offset )
     80                var characterWalker = function( range , matchWord )
    8081                {
    81                         var isCursor = typeof( start.textNode ) !== 'undefined';
    82                         this.textNode = isCursor ? start.textNode : start;
    83                         this.offset = isCursor ? start.offset : offset;
     82                        var walker =
     83                                new CKEDITOR.dom.walker( range );
     84                        walker[ matchWord ? 'guard' : 'evaluator' ] =
     85                                guardDomWalkerNonEmptyTextNode;
     86                        walker.breakOnFalse = true;
     87
    8488                        this._ = {
    85                                 walker : new CKEDITOR.dom.domWalker( this.textNode ),
     89                                matchWord : matchWord,
     90                                walker : walker,
    8691                                matchBoundary : false
    8792                        };
    8893                };
     
    9095                characterWalker.prototype = {
    9196                        next : function()
    9297                        {
     98                                return this.move();     
     99                        },
     100                       
     101                        back : function()
     102                        {
     103                                return this.move( true );
     104                        },
     105                       
     106                        move : function( rtl )
     107                        {
     108                                var currentTextNode = this.textNode;
    93109                                // Already at the end of document, no more character available.
    94                                 if( !this.textNode )
     110                                if(  currentTextNode === null )
    95111                                        return cursorStep.call( this );
    96112
    97113                                this._.matchBoundary = false;
     
    96112
    97113                                this._.matchBoundary = false;
    98114
    99                                 // If there are more characters in the text node, get it and
    100                                 // raise an event.
    101                                 if( this.textNode.type == CKEDITOR.NODE_TEXT
    102                                         && this.offset < this.textNode.getLength() - 1 )
     115                                // There are more characters in the text node, step forward.
     116                                if( currentTextNode
     117                                    && rtl
     118                                        && this.offset > 0 )
    103119                                {
    104                                         this.offset++;
     120                                        this.offset--;
    105121                                        return cursorStep.call( this );
    106122                                }
    107 
    108                                 // If we are at the end of the text node, use dom walker to get
    109                                 // the next text node.
    110                                 var data = null;
    111                                 while ( !data || ( data.node && data.node.type !=
    112                                         CKEDITOR.NODE_TEXT ) )
     123                                else if( currentTextNode
     124                                        && this.offset < currentTextNode.getLength() - 1 )
    113125                                {
    114                                         data = this._.walker.forward(
    115                                                 guardDomWalkerNonEmptyTextNode );
    116 
    117                                         // Block boundary? BR? Document boundary?
    118                                         if ( !data.node
    119                                                 || ( data.node.type !== CKEDITOR.NODE_TEXT
    120                                                         && data.node.getName() in
    121                                                         characterBoundaryElementsEnum ) )
    122                                                 this._.matchBoundary = true;
    123                                 }
    124                                 this.textNode = data.node;
    125                                 this.offset = 0;
    126                                 return cursorStep.call( this );
    127                         },
    128 
    129                         back : function()
    130                         {
    131                                 this._.matchBoundary = false;
    132 
    133                                 // More characters -> decrement offset and return.
    134                                 if ( this.textNode.type == CKEDITOR.NODE_TEXT && this.offset > 0 )
    135                                 {
    136                                         this.offset--;
     126                                        this.offset++;
    137127                                        return cursorStep.call( this );
    138128                                }
    139 
    140                                 // Start of text node -> use dom walker to get the previous text node.
    141                                 var data = null;
    142                                 while ( !data
    143                                 || ( data.node && data.node.type != CKEDITOR.NODE_TEXT ) )
     129                                else
    144130                                {
    145                                         data = this._.walker.reverse( guardDomWalkerNonEmptyTextNode );
     131                                        currentTextNode = null;
     132                                        // At the end of the text node, walking foward for the next.
     133                                        while ( !currentTextNode )
     134                                        {
     135                                                currentTextNode =
     136                                                        this._.walker[ rtl ? 'previous' : 'next' ].call( this._.walker );
    146137
    147                                         // Block boundary? BR? Document boundary?
    148                                         if ( !data.node || ( data.node.type !== CKEDITOR.NODE_TEXT &&
    149                                         data.node.getName() in characterBoundaryElementsEnum ) )
    150                                                 this._.matchBoundary = true;
     138                                                // Stop searching if we're need full word match.
     139                                                if ( this._.matchWord && !currentTextNode )
     140                                                        break;
     141                                                // Marking as match boundaries.
     142                                                if( currentTextNode === false
     143                                                   && checkCharactersBoundary( this._.walker.current ) )
     144                                                        this._.matchBoundary = true;
     145       
     146                                                // Already reach document end.
     147                                                if ( this._.walker._.end )
     148                                                        break;
     149                                        }
     150                                        // Found a fresh text node.
     151                                        this.textNode = currentTextNode;
     152                                        if ( currentTextNode )
     153                                                this.offset = rtl ? currentTextNode.getLength() - 1 : 0;
     154                                        else
     155                                                this.offset = 0;
    151156                                }
    152                                 this.textNode = data.node;
    153                                 this.offset = data.node.length - 1;
     157
    154158                                return cursorStep.call( this );
    155159                        }
     160
    156161                };
    157162
    158163                /**
     
    218223                                // node.
    219224                                if ( endNode.getLength() < 1 )
    220225                                {
    221                                         while ( ( endNode = endNode.getPreviousSourceNode() ) && !( endNode.type == CKEDITOR.NODE_TEXT && endNode.getLength() > 0 ) )
     226                                        while ( ( endNode = endNode.getPreviousSourceNode() )
     227                                                   && !( endNode.type == CKEDITOR.NODE_TEXT
     228                                                                        && endNode.getLength() > 0 ) )
    222229                                        { /*jsl:pass*/ }
    223230
    224231                                        endIndex = endNode.getLength();
     
    224231                                        endIndex = endNode.getLength();
    225232                                }
    226233
    227                                 var cursor = new characterWalker( startNode, startIndex );
    228                                 this._.cursors = [ cursor ];
    229                                 if ( !( cursor.textNode.equals( endNode ) && cursor.offset == endIndex - 1 ) )
     234                                // Rebuild the character range.
     235                                var cursor,
     236                                                walker = new characterWalker(
     237                                                                getRangeAfterCursor(
     238                                                                                                        ( { textNode: startNode, offset : startIndex } ),
     239                                                                                                        true ) );
     240                                this._.cursors = [];
     241                                do
    230242                                {
    231                                         do
    232                                         {
    233                                                 cursor = new characterWalker( cursor );
    234                                                 cursor.next();
    235                                                 this._.cursors.push( cursor );
    236                                         }
    237                                         while ( !( cursor.textNode.equals( endNode ) && cursor.offset == endIndex - 1 ) );
     243                                        cursor = walker.next();
     244                                        this._.cursors.push( cursor );
    238245                                }
    239 
     246                                while ( !( cursor.textNode.equals( endNode )
     247                                                         && cursor.offset == endIndex - 1 ) );
    240248                                this._.rangeLength = this._.cursors.length;
    241249                        },
    242250
     
    338346                                return cursors[ cursors.length - 1 ].character;
    339347                        },
    340348
    341                         getNextRange : function( maxLength )
     349                        getNextCharacterRange : function( maxLength )
    342350                        {
    343                                 var cursors = this._.cursors;
    344                                 if ( cursors.length < 1 )
     351                                var lastCursor,
     352                                                cursors = this._.cursors;
     353                                if ( !( lastCursor = cursors[ cursors.length - 1 ] ) )
    345354                                        return null;
    346 
    347                                 var next = new characterWalker( cursors[ cursors.length - 1 ] );
    348                                 return new characterRange( next, maxLength );
     355                                return new characterRange(
     356                                                                                new characterWalker(
     357                                                                                        getRangeAfterCursor( lastCursor ) ),
     358                                                                                maxLength );
    349359                        },
    350 
     360                       
    351361                        getCursors : function()
    352362                        {
    353363                                return this._.cursors;
     
    354364                        }
    355365                };
    356366
     367               
     368                // The remaining document range after the character cursor.
     369                function getRangeAfterCursor( cursor , inclusive )
     370                {
     371                        var range = new CKEDITOR.dom.range();
     372                        range.setStart( cursor.textNode,
     373                                                   ( inclusive ? cursor.offset : cursor.offset + 1 ) );
     374                        range.setEndAt( editor.document.getBody(),
     375                                                        CKEDITOR.POSITION_BEFORE_END );
     376                        return range;
     377                }
     378
     379                // The document range before the character cursor.
     380                function getRangeBeforeCursor( cursor )
     381                {
     382                        var range = new CKEDITOR.dom.range();
     383                        range.setStartAt( editor.document.getBody(),
     384                                                        CKEDITOR.POSITION_AFTER_START );
     385                        range.setEnd( cursor.textNode, cursor.offset );
     386                        return range;
     387                }
     388               
    357389                var KMP_NOMATCH = 0,
    358390                        KMP_ADVANCED = 1,
    359391                        KMP_MATCHED = 2;
     
    430462                };
    431463
    432464                var finder = {
    433                         startCursor : null,
    434                         range : null,
     465                        searchRange : null,
     466                        matchRange : null,
    435467                        find : function( pattern, matchCase, matchWord, matchCyclic )
    436468                        {
    437                                 if( !this.range )
    438                                         this.range = new characterRange( new characterWalker( this.startCursor ), pattern.length );
     469                                if( !this.matchRange )
     470                                        this.matchRange =
     471                                                new characterRange(
     472                                                        new characterWalker( this.searchRange ),
     473                                                        pattern.length );
    439474                                else
    440475                                {
    441                                         this.range.removeHighlight();
    442                                         this.range = this.range.getNextRange( pattern.length );
     476                                        this.matchRange.removeHighlight();
     477                                        this.matchRange = this.matchRange.getNextCharacterRange( pattern.length );
    443478                                }
    444479
    445480                                var matcher = new kmpMatcher( pattern, !matchCase ),
     
    448483
    449484                                while ( character !== null )
    450485                                {
    451                                         this.range.moveNext();
    452                                         while ( ( character = this.range.getEndCharacter() ) )
     486                                        this.matchRange.moveNext();
     487                                        while ( ( character = this.matchRange.getEndCharacter() ) )
    453488                                        {
    454489                                                matchState = matcher.feedCharacter( character );
    455490                                                if ( matchState == KMP_MATCHED )
     
    454489                                                matchState = matcher.feedCharacter( character );
    455490                                                if ( matchState == KMP_MATCHED )
    456491                                                        break;
    457                                                 if ( this.range.moveNext().hitMatchBoundary )
     492                                                if ( this.matchRange.moveNext().hitMatchBoundary )
    458493                                                        matcher.reset();
    459494                                        }
    460495
     
    462497                                        {
    463498                                                if ( matchWord )
    464499                                                {
    465                                                         var cursors = this.range.getCursors(),
     500                                                        var cursors = this.matchRange.getCursors(),
    466501                                                                tail = cursors[ cursors.length - 1 ],
    467                                                                 head = cursors[ 0 ],
    468                                                                 headWalker = new characterWalker( head ),
    469                                                                 tailWalker = new characterWalker( tail );
    470 
     502                                                                head = cursors[ 0 ];
     503                                                                headWalker =
     504                                                                        new characterWalker(
     505                                                                                getRangeBeforeCursor( head ),
     506                                                                        true ),
     507                                                                tailWalker =
     508                                                                        new characterWalker(
     509                                                                                getRangeAfterCursor( tail ),
     510                                                                        true );
    471511                                                        if ( ! ( isWordSeparator(
    472512                                                                                headWalker.back().character )
    473513                                                                                && isWordSeparator(
     
    475515                                                                continue;
    476516                                                }
    477517
    478                                                 this.range.setMatched();
     518                                                this.matchRange.setMatched();
    479519                                                return true;
    480520                                        }
    481521                                }
     
    480520                                        }
    481521                                }
    482522
    483                                 this.range.clearMatched();
    484 
    485                                 // clear current session and restart from beginning
     523                                this.matchRange.clearMatched();
     524                                this.matchRange.removeHighlight();
     525                                // Clear current session and restart with the default search
     526                                // range.
    486527                                if ( matchCyclic )
    487528                                {
    488                                         this.startCursor = getDefaultStartCursor();
    489                                         this.range = null;
     529                                        this.searchRange = getSearchRange( true );
     530                                        this.matchRange = null;
    490531                                }
    491532
    492533                                return false;
     
    530571                }
    531572
    532573                /**
    533                  * Get cursor that indicate search begin with, receive from user
     574                 * The range in which find/replace happened, receive from user
    534575                 * selection prior.
    535576                 */
    536                 function getStartCursor()
     577                function getSearchRange( isDefault )
    537578                {
    538                         var sel = editor.getSelection();
    539                         if ( sel )
     579                        var searchRange,
     580                                sel = editor.getSelection(),
     581                                body = editor.document.getBody();
     582                        if ( sel && !isDefault )
    540583                        {
    541                                 var lastRange = sel.getRanges()[ sel.getRanges().length - 1 ];
    542                                 return {
    543                                         textNode : lastRange.getBoundaryNodes().endNode,
    544                                         offset : lastRange.endContainer.type ===
    545                                                 CKEDITOR.NODE_ELEMENT ?
    546                                                 0       : lastRange.endOffset
    547                                 };
     584                                searchRange = sel.getRanges()[ 0 ].clone();
     585                                searchRange.collapse( true );
    548586                        }
    549587                        else
    550                                 return getDefaultStartCursor();
     588                        {
     589                                searchRange = new CKEDITOR.dom.range();
     590                                searchRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START );
     591                        }
     592                        searchRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END );
     593                        return searchRange;
    551594                }
    552595
    553596                return {
     
    785828                        onShow : function()
    786829                        {
    787830                                // Establish initial searching start position.
    788                                 finder.startCursor = getStartCursor.call( this );
     831                                finder.searchRange = getSearchRange();
    789832
    790833                                if ( startupPage == 'replace' )
    791834                                        this.getContentElement( 'replace', 'txtFindReplace' ).focus();
     
    794837                        },
    795838                        onHide : function()
    796839                        {
    797                                 if ( finder.range && finder.range.isMatched() )
     840                                if ( finder.matchRange && finder.matchRange.isMatched() )
    798841                                {
    799                                         finder.range.removeHighlight();
     842                                        finder.matchRange.removeHighlight();
    800843                                        editor.focus();
    801844                                        editor.getSelection().selectRanges(
    802                                                 [ finder.range.toDomRange() ] );
     845                                                [ finder.matchRange.toDomRange() ] );
    803846                                }
    804847
    805848                                // Clear current session before dialog close
    806                                 delete finder.range;
     849                                delete finder.matchRange;
    807850                        }
    808851                };
    809852        };
  • _source/core/loader.js

     
    3939                        'core/dom/node'                 : [ 'core/dom/domobject', 'core/tools' ],
    4040                        'core/dom/nodelist'             : [ 'core/dom/node' ],
    4141                        'core/dom/domobject'    : [ 'core/dom/event' ],
    42                         'core/dom/domwalker'    : [ 'core/dom/node', 'core/dom/element', 'core/dom/document' ],
    43                         'core/dom/range'                : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/domwalker', 'core/dom/walker' ],
     42                        'core/dom/range'                : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/walker' ],
    4443                        'core/dom/text'                 : [ 'core/dom/node', 'core/dom/domobject' ],
    4544                        'core/dom/walker'               : [ 'core/dom/node' ],
    4645                        'core/dom/window'               : [ 'core/dom/domobject' ],
  • _source/core/dom/range.js

     
    10871099
    10881100                                case CKEDITOR.ENLARGE_BLOCK_CONTENTS:
    10891101                                case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS:
    1090                                         // DFS backward to get the block/list item boundary at or before the start.
    1091 
    1092                                         // Get the boundaries nodes.
    1093                                         var startNode = this.getTouchedStartNode(),
    1094                                                 endNode = this.getTouchedEndNode();
    1095 
    1096                                         if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.isBlockBoundary() )
    1097                                         {
    1098                                                 this.setStartAt( startNode,
    1099                                                         CKEDITOR.dtd.$empty[ startNode.getName() ] ?
    1100                                                                 CKEDITOR.POSITION_AFTER_END :
    1101                                                                 CKEDITOR.POSITION_AFTER_START );
    1102                                         }
    1103                                         else
    1104                                         {
    1105                                                 // Get the function used to check the enlaarging limits.
    1106                                                 var guardFunction = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ?
    1107                                                                 CKEDITOR.dom.domWalker.blockBoundary() :
    1108                                                                 CKEDITOR.dom.domWalker.listItemBoundary() );
    1109 
    1110                                                 // Create the DOM walker, which will traverse the DOM.
    1111                                                 var walker = new CKEDITOR.dom.domWalker( startNode );
    1112 
    1113                                                 // Go walk in reverse sense.
    1114                                                 var data = walker.reverse( guardFunction );
    1115 
    1116                                                 var boundaryEvent = data.events.shift();
    11171102
    1118                                                 this.setStartBefore( boundaryEvent.from );
    1119                                         }
     1103                                        // Enlarging the start boundary.
     1104                                        var walkerRange = new CKEDITOR.dom.range( this.document );
     1105                                        walkerRange.setStartAt(
     1106                                                this.document.getBody(), CKEDITOR.POSITION_AFTER_START );
     1107                                        walkerRange.setEnd( this.startContainer, this.startOffset );
     1108                                        var walker = new CKEDITOR.dom.walker( walkerRange ),
     1109                                                blockGuard =
     1110                                                        CKEDITOR.dom.walker.blockBoundary(
     1111                                                                CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ? { br : 1 } : null ),
     1112                                                enlargeable;
     1113                                        walker.guard = blockGuard;
     1114                                        if ( ( enlargeable = walker.lastBackward() ) )
     1115                                                this.setStartAt(
     1116                                                        enlargeable, CKEDITOR.POSITION_BEFORE_START );
    11201117
    1121                                         if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.isBlockBoundary() )
    1122                                         {
    1123                                                 this.setEndAt( endNode,
    1124                                                         CKEDITOR.dtd.$empty[ endNode.getName() ] ?
    1125                                                                 CKEDITOR.POSITION_BEFORE_START :
    1126                                                                 CKEDITOR.POSITION_BEFORE_END );
    1127                                         }
    1128                                         else
    1129                                         {
    1130                                                 // DFS forward to get the block/list item boundary at or before the end.
    1131                                                 walker.setNode( endNode );
    1132                                                 data = walker.forward( guardFunction );
    1133                                                 boundaryEvent = data.events.shift();
    1134 
    1135                                                 this.setEndAfter( boundaryEvent.from );
    1136                                         }
     1118                                        // Enlaring the end boundary.
     1119                                        walkerRange = this.clone();
     1120                                        walkerRange.collapse();
     1121                                        walkerRange.setEndAt(
     1122                                                this.document.getBody(), CKEDITOR.POSITION_BEFORE_END );
     1123                                        walker = new CKEDITOR.dom.walker( walkerRange );
     1124                                        walker.guard = blockGuard;
     1125                                        if ( ( enlargeable = walker.lastForward() ) )
     1126                                                this.setEndAt( enlargeable, CKEDITOR.POSITION_AFTER_END );
    11371127                        }
    11381128                },
    11391129
  • _source/core/dom/walker.js

     
    66(function()
    77{
    88        // This function is to be called under a "walker" instance scope.
    9         function iterate( rtl, breakOnFalse )
     9        function iterate( rtl, forceBreakOnFalse )
    1010        {
    1111                // Return null if we have reached the end.
    1212                if ( this._.end )
     
    124124
    125125                        if ( !this.evaluator || this.evaluator( node ) !== false )
    126126                                return node;
    127                         else if ( breakOnFalse && this.evaluator )
     127                        else if ( ( forceBreakOnFalse || this.breakOnFalse ) && this.evaluator )
    128128                                return false;
    129129
    130130                        node = node[ getSourceNodeFn ]( false, type, guard );
     
    134134                return this.current = null;
    135135        }
    136136
    137 //      function iterateToLast( rtl )
    138 //      {
    139 //              var node, last = null;
     137        function iterateToLast( rtl )
     138        {
     139                var node, last = null;
    140140
    141 //              while ( node = iterate.call( this, rtl ) )
    142 //                      last = node;
     141                while ( node = iterate.call( this, rtl ) )
     142                        last = node;
    143143
    144 //              return last;
    145 //      }
     144                return last;
     145        }
    146146
    147147        CKEDITOR.dom.walker = CKEDITOR.tools.createClass(
    148148        {
     
    177177                         * it's to be considered into the walk or not. If not provided, all
    178178                         * matched nodes are considered good.
    179179                         * If the function returns "false" the node is ignored.
    180                          * @name CKEDITOR.pluginDefinition.prototype.evaluator
     180                         * @name CKEDITOR.dom.walker.prototype.evaluator
    181181                         * @property
    182182                         * @type Function
    183183                         */
     
    189189                         * entering and exiting nodes, as well as for the matched nodes.
    190190                         * If this function returns "false", the walking ends and no more
    191191                         * nodes are evaluated.
    192                          * @name CKEDITOR.pluginDefinition.prototype.guard
     192                         * @name CKEDITOR.dom.walker.prototype.guard
    193193                         * @property
    194194                         * @type Function
    195195                         */
     
    194194                         * @type Function
    195195                         */
    196196                        // this.guard = null;
    197 
     197                       
     198                        /**
     199                         * Whether the iteration return 'false' when the specified
     200                         * {@link CKEDITOR.dom.walker.prototype.evaluator} failed.
     201                         *@name CKEDITOR.dom.walker.prototype.breakOnFalse
     202                         *@property
     203                         *@type Boolean
     204                         */
     205                        // this.breakOnFalse = false;
     206                       
    198207                        /** @private */
    199208                        this._ = {};
    200209                },
    201 
     210//
    202211//              statics :
    203212//              {
    204213//                      /* Creates a CKEDITOR.dom.walker instance to walk inside DOM boundaries set by nodes.
     
    214223//                      createOnNodes : function( startNode, endNode, startInclusive, endInclusive )
    215224//                      {
    216225//                              var range = new CKEDITOR.dom.range();
    217 //                              range.setStartAt( startNode, startInclusive ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_END ) ;
    218 
     226//                              if ( startNode )
     227//                                      range.setStartAt( startNode, startInclusive ? CKEDITOR.POSITION_BEFORE_START : CKEDITOR.POSITION_AFTER_END ) ;
     228//                              else
     229//                                      range.setStartAt( startNode.getDocument().getBody(), CKEDITOR.POSITION_AFTER_START ) ;
     230//
    219231//                              if ( endNode )
    220232//                                      range.setEndAt( endNode, endInclusive ? CKEDITOR.POSITION_AFTER_END : CKEDITOR.POSITION_BEFORE_START ) ;
    221233//                              else
     
    220232//                                      range.setEndAt( endNode, endInclusive ? CKEDITOR.POSITION_AFTER_END : CKEDITOR.POSITION_BEFORE_START ) ;
    221233//                              else
    222234//                                      range.setEndAt( startNode.getDocument().getBody(), CKEDITOR.POSITION_BEFORE_END ) ;
    223 
     235//
    224236//                              return new CKEDITOR.dom.walker( range );
    225237//                      }
    226238//              },
    227 
     239//
    228240                proto :
    229241                {
    230242                        /**
     
    274286                        checkBackward : function()
    275287                        {
    276288                                return iterate.call( this, true, true ) !== false;
    277                         }
     289                        },
    278290
    279 // The following features have been originally included in the implementation,
    280 // but they are not used anywhere in the code, so they got commented out.
    281291
    282 //                      /**
    283 //                       * Executes a full walk forward (to the right), until no more nodes
    284 //                       * are available, returning the last valid node.
    285 //                       * @returns {CKEDITOR.dom.node} The last node at the right or null
    286 //                       *              if no valid nodes are available.
    287 //                       */
    288 //                      lastForward : function()
    289 //                      {
    290 //                              return iterateToLast.call( this );
    291 //                      },
     292                        /**
     293                         * Executes a full walk forward (to the right), until no more nodes
     294                         * are available, returning the last valid node.
     295                         * @returns {CKEDITOR.dom.node} The last node at the right or null
     296                         *              if no valid nodes are available.
     297                         */
     298                        lastForward : function()
     299                        {
     300                                return iterateToLast.call( this );
     301                        },
    292302
    293 //                      /**
    294 //                       * Executes a full walk backwards (to the left), until no more nodes
    295 //                       * are available, returning the last valid node.
    296 //                       * @returns {CKEDITOR.dom.node} The last node at the left or null
    297 //                       *              if no valid nodes are available.
    298 //                       */
    299 //                      lastBackward : function()
    300 //                      {
    301 //                              return iterateToLast.call( this, true );
    302 //                      }
     303                        /**
     304                         * Executes a full walk backwards (to the left), until no more nodes
     305                         * are available, returning the last valid node.
     306                         * @returns {CKEDITOR.dom.node} The last node at the left or null
     307                         *              if no valid nodes are available.
     308                         */
     309                        lastBackward : function()
     310                        {
     311                                return iterateToLast.call( this, true );
     312                        }
     313
    303314                }
    304315        });
     316
     317        /*
     318         * Anything whose display computed style is block, list-item, table,
     319         * table-row-group, table-header-group, table-footer-group, table-row,
     320         * table-column-group, table-column, table-cell, table-caption, or whose node
     321         * name is hr, br (when enterMode is br only) is a block boundary.
     322         */
     323        var blockBoundaryDisplayMatch =
     324        {
     325                block : 1,
     326                'list-item' : 1,
     327                table : 1,
     328                'table-row-group' : 1,
     329                'table-header-group' : 1,
     330                'table-footer-group' : 1,
     331                'table-row' : 1,
     332                'table-column-group' : 1,
     333                'table-column' : 1,
     334                'table-cell' : 1,
     335                'table-caption' : 1
     336        },
     337        blockBoundaryNodeNameMatch = { hr : 1 };
     338
     339        CKEDITOR.dom.element.prototype.isBlockBoundary = function( customNodeNames )
     340        {
     341                var nodeNameMatches = CKEDITOR.tools.extend(
     342                        blockBoundaryNodeNameMatch, customNodeNames || {} );
     343
     344                return blockBoundaryDisplayMatch[ this.getComputedStyle( 'display' ) ] ||
     345                        nodeNameMatches[ this.getName() ];
     346        };
     347
     348        CKEDITOR.dom.walker.blockBoundary = function( customNodeNames )
     349        {
     350                return function( node , type )
     351                {
     352                        return ! ( node.type == CKEDITOR.NODE_ELEMENT
     353                                                && node.isBlockBoundary( customNodeNames ) );
     354                };
     355        };
     356       
     357        CKEDITOR.dom.walker.listItemBoundary = function()
     358        {
     359                        return this.blockBoundary( { br : 1 } );
     360        };
     361
    305362})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy