Ticket #5614: 5614.patch

File 5614.patch, 5.2 KB (added by Garry Yao, 16 years ago)
  • _source/core/dom/text.js

     
    119119                                return this.$.nodeValue.substr( indexA );
    120120                        else
    121121                                return this.$.nodeValue.substring( indexA, indexB );
     122                },
     123
     124                /**
     125                 * Whether the text node contains only empty-space AND has no visual impacts.
     126                 */
     127                isEmptySpaces : function()
     128                {
     129                        return !( CKEDITOR.tools.trim( this.getText() )
     130                                || this.getAscendant( 'pre' ) );
    122131                }
    123132        });
  • _source/core/dom/node.js

     
    209209                                {
    210210                                        for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
    211211                                        {
    212                                                 var candidate = parentNode.childNodes[i];
     212                                                var candidate = new CKEDITOR.dom.node( parentNode.childNodes[ i ] );
    213213
     214                                                if ( candidate.type == CKEDITOR.NODE_TEXT
     215                                                        && candidate.isEmptySpaces() )
     216                                                {
     217                                                        continue;
     218                                                }
     219
    214220                                                if ( normalized &&
    215                                                                 candidate.nodeType == 3 &&
    216                                                                 candidate.previousSibling &&
    217                                                                 candidate.previousSibling.nodeType == 3 )
     221                                                                candidate.type == CKEDITOR.NODE_TEXT &&
     222                                                                candidate.getPrevious() &&
     223                                                                candidate.getPrevious().type == CKEDITOR.NODE_TEXT )
    218224                                                {
    219225                                                        continue;
    220226                                                }
    221227
    222228                                                currentIndex++;
    223229
    224                                                 if ( candidate == node )
     230                                                if ( candidate.$ == node )
    225231                                                        break;
    226232                                        }
    227233
  • _source/core/dom/range.js

     
    500500                                        startOffset += previous.getLength();
    501501                                }
    502502
     503                                // Exclude empty-spaces-only nodes from start. (#5614)
     504                                var previousOffset = startOffset - 1;
     505                                while ( startContainer.type == CKEDITOR.NODE_ELEMENT
     506                                                && previousOffset >= 0 )
     507                                {
     508                                        var child = startContainer.getChild( previousOffset-- );
     509                                        if ( child.type == CKEDITOR.NODE_TEXT
     510                                                && child.isEmptySpaces() )
     511                                                startOffset--;
     512                                }
     513
    503514                                // Process the end only if not normalized.
    504515                                if ( !this.isCollapsed )
    505516                                {
     
    527538                                                endContainer = previous;
    528539                                                endOffset += previous.getLength();
    529540                                        }
    530                                 }
    531                         }
     541
     542                                        // Exclude empty-spaces-only nodes from end. (#5614)
     543                                        previousOffset = endOffset - 1;
     544                                        while ( endContainer.type == CKEDITOR.NODE_ELEMENT
     545                                                        && previousOffset >= 0 )
     546                                        {
     547                                                child = endContainer.getChild( previousOffset-- );
     548                                                if ( child.type == CKEDITOR.NODE_TEXT
     549                                                        && child.isEmptySpaces() )
     550                                                        endOffset--;
     551                                        }
     552                                }
     553                        }
    532554
    533555                        return {
    534556                                start           : startContainer.getAddress( normalized ),
     
    552574                                var endContainer        = bookmark.end && this.document.getByAddress( bookmark.end, bookmark.normalized ),
    553575                                        endOffset       = bookmark.endOffset;
    554576
     577                                if ( startContainer.type == CKEDITOR.NODE_ELEMENT )
     578                                {
     579                                        var children = startContainer.getChildren();
     580                                        for ( var i = 0, count = children.count(); i < count ; i++ )
     581                                        {
     582                                                var child = children.getItem( i );
     583                                                if ( child.type == CKEDITOR.NODE_TEXT
     584                                                        && child.isEmptySpaces() )
     585                                                {
     586                                                        startOffset--;
     587                                                }
     588                                        }
     589                                }
     590
    555591                                // Set the start boundary.
    556592                                this.setStart( startContainer, startOffset );
    557593
    558594                                // Set the end boundary. If not available, collapse it.
    559595                                if ( endContainer )
     596                                {
     597                                        if ( endContainer.type == CKEDITOR.NODE_ELEMENT )
     598                                        {
     599                                                children = endContainer.getChildren();
     600                                                for ( i = 0, count = children.count(); i < count ; i++ )
     601                                                {
     602                                                        child = children.getItem( i );
     603                                                        if ( child.type == CKEDITOR.NODE_TEXT
     604                                                                && child.isEmptySpaces() )
     605                                                        {
     606                                                                endOffset--;
     607                                                        }
     608                                                }
     609                                        }
     610
    560611                                        this.setEnd( endContainer, endOffset );
     612                                }
    561613                                else
     614                                {
    562615                                        this.collapse( true );
    563                         }
     616                                }
     617                        }
    564618                        else                                    // Created with createBookmark().
    565619                        {
    566620                                var serializable = bookmark.serializable,
  • _source/core/dom/document.js

     
    125125
    126126                                for (var j = 0 ; j < $.childNodes.length ; j++ )
    127127                                {
    128                                         var candidate = $.childNodes[ j ];
     128                                        var candidate = new CKEDITOR.dom.node( $.childNodes[ j ] );
    129129
    130130                                        if ( normalized === true &&
    131                                                         candidate.nodeType == 3 &&
    132                                                         candidate.previousSibling &&
    133                                                         candidate.previousSibling.nodeType == 3 )
     131                                                        candidate.type == CKEDITOR.NODE_TEXT &&
     132                                                        candidate.getPrevious() &&
     133                                                        candidate.getPrevious().type == CKEDITOR.NODE_TEXT )
    134134                                        {
    135135                                                continue;
    136136                                        }
    137137
     138                                        if ( candidate.type == CKEDITOR.NODE_TEXT
     139                                                && candidate.isEmptySpaces() )
     140                                        {
     141                                                continue;
     142                                        }
     143
    138144                                        currentIndex++;
    139145
    140146                                        if ( currentIndex == target )
    141147                                        {
    142                                                 $ = candidate;
     148                                                $ = candidate.$;
    143149                                                break;
    144150                                        }
    145151                                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy