Ticket #3304: 3304.patch

File 3304.patch, 10.7 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                if ( node.type == CKEDITOR.NODE_TEXT && node.$.length > 0 )
     11                        return true;
     12                else
     13                        return false;
     14        }
    1415
    15         var guardDomWalkerNonEmptyTextNode = function( evt )
     16        /**
     17         * Elements which break characters been considered as sequence.
     18        */
     19        function checkCharactersBoundary ( node )
    1620        {
    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 
     21                var dtd = CKEDITOR.dtd;
     22                return node.isBlockBoundary(
     23                        CKEDITOR.tools.extend( {}, dtd.$empty, dtd.$nonEditable ) );
     24        }
    2325
    2426        /**
    2527         * Get the cursor object which represent both current character and it's dom
     
    7577                 * Iterator which walk through document char by char.
    7678                 * @param {Object} start
    7779                 * @param {Number} offset
     80                 * @param {Boolean} isStrict
    7881                 */
    79                 var characterWalker = function( start, offset )
     82                var characterWalker = function( start, offset , isStrict )
    8083                {
    8184                        var isCursor = typeof( start.textNode ) !== 'undefined';
    8285                        this.textNode = isCursor ? start.textNode : start;
     
    8184                        var isCursor = typeof( start.textNode ) !== 'undefined';
    8285                        this.textNode = isCursor ? start.textNode : start;
    8386                        this.offset = isCursor ? start.offset : offset;
     87                        var walker = new CKEDITOR.dom.walker( this.textNode );
     88                        walker[ isStrict? 'guard' : 'evaluator' ] =
     89                                guardDomWalkerNonEmptyTextNode;
    8490                        this._ = {
    85                                 walker : new CKEDITOR.dom.domWalker( this.textNode ),
     91                                walker : walker,
    8692                                matchBoundary : false
    8793                        };
    8894                };
     
    107113
    108114                                // If we are at the end of the text node, use dom walker to get
    109115                                // the next text node.
    110                                 var data = null;
    111                                 while ( !data || ( data.node && data.node.type !=
    112                                         CKEDITOR.NODE_TEXT ) )
     116                                var node = null;
     117                                while ( !node )
    113118                                {
    114                                         data = this._.walker.forward(
    115                                                 guardDomWalkerNonEmptyTextNode );
     119                                        node = this._.walker.next( true );
    116120
    117                                         // Block boundary? BR? Document boundary?
    118                                         if ( !data.node
    119                                                 || ( data.node.type !== CKEDITOR.NODE_TEXT
    120                                                         && data.node.getName() in
    121                                                         characterBoundaryElementsEnum ) )
     121                                        // Marking as match boundaries.
     122                                        if( node === false
     123                                           && checkCharactersBoundary( this._.walker.current ) )
    122124                                                this._.matchBoundary = true;
     125                                        // Already reach document end.
     126                                        if ( !this._.walker.current )
     127                                                break;
     128                                       
    123129                                }
    124                                 this.textNode = data.node;
     130                                this.textNode = node;
    125131                                this.offset = 0;
    126132                                return cursorStep.call( this );
    127133                        },
     
    138144                                }
    139145
    140146                                // 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 ) )
     147                                var node = null;
     148                                while ( !node )
    144149                                {
    145                                         data = this._.walker.reverse( guardDomWalkerNonEmptyTextNode );
     150                                        node = this._.walker.previous( true );
    146151
    147                                         // Block boundary? BR? Document boundary?
    148                                         if ( !data.node || ( data.node.type !== CKEDITOR.NODE_TEXT &&
    149                                         data.node.getName() in characterBoundaryElementsEnum ) )
     152                                        // Marking as match boundaries.
     153                                        if( node === false
     154                                                && checkCharactersBoundary( this._.walker.current ) )
    150155                                                this._.matchBoundary = true;
     156                                       
     157                                        // Already reach document end.
     158                                        if ( !this._.walker.current )
     159                                                break;
    151160                                }
    152                                 this.textNode = data.node;
    153                                 this.offset = data.node.length - 1;
     161                                this.textNode = node;
     162                                this.offset = node.length - 1;
    154163                                return cursorStep.call( this );
    155164                        }
    156165                };
     
    465474                                                        var cursors = this.range.getCursors(),
    466475                                                                tail = cursors[ cursors.length - 1 ],
    467476                                                                head = cursors[ 0 ],
    468                                                                 headWalker = new characterWalker( head ),
    469                                                                 tailWalker = new characterWalker( tail );
     477                                                                headWalker = new characterWalker( head, null, true ),
     478                                                                tailWalker = new characterWalker( tail, null, true );
    470479
    471480                                                        if ( ! ( isWordSeparator(
    472481                                                                                headWalker.back().character )
  • _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

     
    10871087
    10881088                                        // Get the boundaries nodes.
    10891089                                        var startNode = this.getTouchedStartNode(),
    1090                                                 endNode = this.getTouchedEndNode();
     1090                                                endNode = this.getTouchedEndNode(),
     1091                                                // Create the DOM walker, which will traverse the DOM.
     1092                                                walker = new CKEDITOR.dom.walker();
     1093                                                // Get the function used to check the enlaarging limits.
     1094                                                walker.guard = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ?
     1095                                                                CKEDITOR.dom.walker.blockBoundary() :
     1096                                                                CKEDITOR.dom.walker.listItemBoundary() );
    10911097
    10921098                                        if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.isBlockBoundary() )
    10931099                                        {
     
    10981104                                        }
    10991105                                        else
    11001106                                        {
    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 );
    1108 
     1107                                                walker.startNode = startNode;
    11091108                                                // Go walk in reverse sense.
    1110                                                 var data = walker.reverse( guardFunction );
    1111 
    1112                                                 var boundaryEvent = data.events.shift();
    1113 
    1114                                                 this.setStartBefore( boundaryEvent.from );
     1109                                                var node = walker.lastBackward();
     1110                                                this.setStartBefore( node );
    11151111                                        }
    11161112
    11171113                                        if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.isBlockBoundary() )
     
    11241120                                        else
    11251121                                        {
    11261122                                                // 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();
     1123                                                walker.reset();
     1124                                                walker.startNode = endNode;
    11301125
    1131                                                 this.setEndAfter( boundaryEvent.from );
     1126                                                // Get the function used to check the enlaarging limits.
     1127                                                node = walker.lastForward();
     1128                                                this.setEndAfter( node );
    11321129                                        }
    11331130                        }
    11341131                },
  • _source/core/dom/walker.js

     
    4444                                node = null;
    4545                }
    4646                else
    47                         node = this.startNode[ getSourceNodeFn ]( true, type, guard );
     47                        node = this.startNode[ getSourceNodeFn ]( false, type, guard );
    4848
    4949                while ( node && !this._.end )
    5050                {
     
    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;
     
    162162                         * @returns {CKEDITOR.dom.node} The next node or null if no more
    163163                         *              nodes are available.
    164164                         */
    165                         next : function()
     165                        next : function( isGreedy )
    166166                        {
    167                                 return iterate.call( this );
     167                                return iterate.call( this , false, isGreedy );
    168168                        },
    169169
    170170                        /**
     
    172172                         * @returns {CKEDITOR.dom.node} The previous node or null if no more
    173173                         *              nodes are available.
    174174                         */
    175                         previous : function()
     175                        previous : function( isGreedy )
    176176                        {
    177                                 return iterate.call( this, true );
     177                                return iterate.call( this, true, isGreedy );
    178178                        },
    179179
    180180                        /**
     
    217217                        checkBackward : function()
    218218                        {
    219219                                return iterate.call( this, true, true ) !== false;
     220                        },
     221                       
     222                        /**
     223                         * Reset walker to initial state.
     224                         */
     225                        reset : function()
     226                        {
     227                                delete this._.end;
     228                                delete this.current;
    220229                        }
    221230                }
    222231        });
     232
     233        /*
     234         * Anything whose display computed style is block, list-item, table,
     235         * table-row-group, table-header-group, table-footer-group, table-row,
     236         * table-column-group, table-column, table-cell, table-caption, or whose node
     237         * name is hr, br (when enterMode is br only) is a block boundary.
     238         */
     239        var blockBoundaryDisplayMatch =
     240        {
     241                block : 1,
     242                'list-item' : 1,
     243                table : 1,
     244                'table-row-group' : 1,
     245                'table-header-group' : 1,
     246                'table-footer-group' : 1,
     247                'table-row' : 1,
     248                'table-column-group' : 1,
     249                'table-column' : 1,
     250                'table-cell' : 1,
     251                'table-caption' : 1
     252        },
     253        blockBoundaryNodeNameMatch = { hr : 1 };
     254
     255        CKEDITOR.dom.element.prototype.isBlockBoundary = function( customNodeNames )
     256        {
     257                var nodeNameMatches = CKEDITOR.tools.extend(
     258                        blockBoundaryNodeNameMatch, customNodeNames || {} );
     259
     260                return blockBoundaryDisplayMatch[ this.getComputedStyle( 'display' ) ] ||
     261                        nodeNameMatches[ this.getName() ];
     262        };
     263
     264        CKEDITOR.dom.walker.blockBoundary = function( customNodeNames )
     265        {
     266                return function( node , type )
     267                {
     268                        return ! ( node.type == CKEDITOR.NODE_ELEMENT
     269                                                && node.isBlockBoundary( customNodeNames ) );
     270                };
     271        };
     272       
     273        CKEDITOR.dom.walker.listItemBoundary = function()
     274        {
     275                        return this.blockBoundary( { br : 1 } );
     276        };
     277
    223278})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy