Changeset 1078

Show
Ignore:
Timestamp:
2007-11-14 05:23:44 (2 years ago)
Author:
martinkou
Message:

Fixed #1521 : Fixed the issue where the Replace function would spit out JavaScript errors.
Fixed an algorithm bug with FCKDomRange.CreateBookmark2() which causes incorrect addresses to be returned in bookmarks.

Location:
FCKeditor/trunk/editor
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/dialog/fck_replace.html

    r1077 r1078  
    104104function GetData( bookmark ) 
    105105{ 
    106         var currentNode = oEditor.FCK.EditorDocument.documentElement; 
    107         for( var i = 0 ; i < bookmark.length ; i++ ) 
    108         { 
    109                 if ( currentNode.childNodes.length > bookmark[i] ) 
    110                         currentNode = currentNode.childNodes.item( bookmark[i] ) ; 
    111                 else if ( currentNode.nodeType == 3 )   // text node 
     106        var cursor = oEditor.FCK.EditorDocument.documentElement ; 
     107        for ( var i = 0 ; i < bookmark.length ; i++ ) 
     108        { 
     109                var target = bookmark[i] ; 
     110                var currentIndex = -1 ; 
     111                if ( cursor.nodeType != 3 ) 
    112112                { 
    113                         var c = currentNode.nodeValue.charAt( bookmark[i] ) ; 
    114                         if ( i == bookmark.length - 1 ) 
    115                                 return c != "" ? c : null ; 
    116                         else 
     113                        for (var j = 0 ; j < cursor.childNodes.length ; j++ ) 
     114                        { 
     115                                var candidate = cursor.childNodes[j] ; 
     116                                if ( candidate.nodeType == 3 && 
     117                                                candidate.previousSibling && 
     118                                                candidate.previousSibling.nodeType == 3 ) 
     119                                        continue ; 
     120                                currentIndex++ ; 
     121                                if ( currentIndex == target ) 
     122                                { 
     123                                        cursor = candidate ; 
     124                                        break ; 
     125                                } 
     126                        } 
     127                        if ( currentIndex < target ) 
    117128                                return null ; 
    118129                } 
    119130                else 
    120                         return null; 
    121         } 
    122         return currentNode ; 
     131                { 
     132                        if ( i != bookmark.length - 1 ) 
     133                                return null ; 
     134                        while ( target >= cursor.length && cursor.nextSibling && cursor.nextSibling.nodeType == 3 ) 
     135                        { 
     136                                target -= cursor.length ; 
     137                                cursor = cursor.nextSibling ; 
     138                        } 
     139                        cursor = cursor.nodeValue.charAt( target ) ; 
     140                        if ( cursor == "" ) 
     141                                cursor = null ; 
     142                } 
     143        } 
     144        return cursor ; 
    123145} 
    124146 
     
    128150        // See if there's anything further down the tree. 
    129151        var next = bookmark.concat( [0] ) ; 
    130  
    131152        if ( GetData( next ) != null ) 
    132153                return next ; 
  • FCKeditor/trunk/editor/_source/classes/fckdomrange.js

    r1048 r1078  
    441441                        "End" : [ this._Range.endOffset ] 
    442442                } ; 
     443                // Since we're treating the document tree as normalized, we need to backtrack the text lengths 
     444                // of previous text nodes into the offset value. 
    443445                var curStart = this._Range.startContainer.previousSibling ; 
    444446                var curEnd = this._Range.endContainer.previousSibling ; 
     447 
     448                // Also note that the node that we use for "address base" would change during backtracking. 
     449                var addrStart = this._Range.startContainer ; 
     450                var addrEnd = this._Range.endContainer ; 
    445451                while ( curStart && curStart.nodeType == 3 ) 
    446452                { 
    447453                        bookmark.Start[0] += curStart.length ; 
     454                        addrStart = curStart ; 
    448455                        curStart = curStart.previousSibling ; 
    449456                } 
     
    451458                { 
    452459                        bookmark.End[0] += curEnd.length ; 
     460                        addrEnd = curEnd ; 
    453461                        curEnd = curEnd.previousSibling ; 
    454462                } 
    455463                // Then, we record down the precise position of the container nodes 
    456464                // by walking up the DOM tree and counting their childNode index 
    457                 bookmark.Start = FCKDomTools.GetNodeAddress( this._Range.startContainer, true ).concat( bookmark.Start ) ; 
    458                 bookmark.End = FCKDomTools.GetNodeAddress( this._Range.endContainer, true ).concat( bookmark.End ) ; 
     465                bookmark.Start = FCKDomTools.GetNodeAddress( addrStart, true ).concat( bookmark.Start ) ; 
     466                bookmark.End = FCKDomTools.GetNodeAddress( addrEnd, true ).concat( bookmark.End ) ; 
    459467                return bookmark; 
    460468        },