Changeset 969

Show
Ignore:
Timestamp:
2007-10-04 06:12:46 (2 years ago)
Author:
martinkou
Message:

Fixed #1331 : FCKDomRange.MoveToBookmark2() and FCKDomRange.CreateBookmark2() will now process the DOM tree as if it is normalized.

Location:
FCKeditor/trunk/editor/_source
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/_source/classes/fckdomrange.js

    r906 r969  
    369369                        "End" : [ this._Range.endOffset ] 
    370370                } ; 
     371                var curStart = this._Range.startContainer.previousSibling ; 
     372                var curEnd = this._Range.endContainer.previousSibling ; 
     373                while ( curStart && curStart.nodeType == 3 ) 
     374                { 
     375                        bookmark.Start[0] += curStart.length ; 
     376                        curStart = curStart.previousSibling ; 
     377                } 
     378                while ( curEnd && curEnd.nodeType == 3 ) 
     379                { 
     380                        bookmark.End[0] += curEnd.length ; 
     381                        curEnd = curEnd.previousSibling ; 
     382                } 
    371383                // Then, we record down the precise position of the container nodes 
    372384                // by walking up the DOM tree and counting their childNode index 
    373                 bookmark.Start = FCKDomTools.GetNodeAddress( this._Range.startContainer ).concat( bookmark.Start ) ; 
    374                 bookmark.End = FCKDomTools.GetNodeAddress( this._Range.endContainer ).concat( bookmark.End ) ; 
     385                bookmark.Start = FCKDomTools.GetNodeAddress( this._Range.startContainer, true ).concat( bookmark.Start ) ; 
     386                bookmark.End = FCKDomTools.GetNodeAddress( this._Range.endContainer, true ).concat( bookmark.End ) ; 
    375387                return bookmark; 
    376388        }, 
     
    379391        { 
    380392                // Reverse the childNode counting algorithm in CreateBookmark2() 
    381                 var curStart = FCKDomTools.GetNodeFromAddress( this.Window.document, bookmark.Start.slice( 0, -1 ) ) ; 
    382                 var curEnd = FCKDomTools.GetNodeFromAddress( this.Window.document, bookmark.End.slice( 0, -1 ) ) ; 
     393                var curStart = FCKDomTools.GetNodeFromAddress( this.Window.document, bookmark.Start.slice( 0, -1 ), true ) ; 
     394                var curEnd = FCKDomTools.GetNodeFromAddress( this.Window.document, bookmark.End.slice( 0, -1 ), true ) ; 
    383395 
    384396                // Generate the W3C Range object and update relevant data 
    385397                this.Release( true ) ; 
    386398                this._Range = new FCKW3CRange( this.Window.document ) ; 
    387                 this._Range.setStart( curStart, bookmark.Start[ bookmark.Start.length - 1 ] ) ; 
    388                 this._Range.setEnd( curEnd, bookmark.End[ bookmark.End.length - 1 ] ) ; 
     399                var startOffset = bookmark.Start[ bookmark.Start.length - 1 ] ; 
     400                var endOffset = bookmark.End[ bookmark.End.length - 1 ] ; 
     401                while ( curStart.nodeType == 3 && startOffset > curStart.length ) 
     402                { 
     403                        if ( ! curStart.nextSibling || curStart.nextSibling.nodeType != 3 ) 
     404                                break ; 
     405                        startOffset -= curStart.length ; 
     406                        curStart = curStart.nextSibling ; 
     407                } 
     408                while ( curEnd.nodeType == 3 && endOffset > curEnd.length ) 
     409                { 
     410                        if ( ! curEnd.nextSibling || curEnd.nextSibling.nodeType != 3 ) 
     411                                break ; 
     412                        endOffset -= curEnd.length ; 
     413                        curEnd = curEnd.nextSibling ; 
     414                } 
     415                this._Range.setStart( curStart, startOffset ) ; 
     416                this._Range.setEnd( curEnd, endOffset ) ; 
    389417                this._UpdateElementInfo() ; 
    390418        }, 
  • FCKeditor/trunk/editor/_source/commandclasses/fckjustifycommands.js

    r968 r969  
    3030        this.IsDefaultAlign = ( alignValue == 'left' && contentDir == 'ltr' ) || 
    3131                                                  ( alignValue == 'right' && contentDir == 'rtl' ) ; 
    32  
    33  
    3432 
    3533        // Get the class name to be used by this instance. 
  • FCKeditor/trunk/editor/_source/internals/fckdomtools.js

    r922 r969  
    550550         * The tree address cannot be used for finding back the DOM tree node once the DOM tree structure has been modified. 
    551551         */ 
    552         GetNodeAddress : function( node ) 
     552        GetNodeAddress : function( node, normalized ) 
    553553        { 
    554554                var retval = [] ; 
    555555                while ( node && node != node.ownerDocument.documentElement ) 
    556556                { 
    557                         retval.unshift( this.GetIndexOf( node ) ) ; 
     557                        var parentNode = node.parentNode ; 
     558                        var currentIndex = -1 ; 
     559                        for( var i = 0 ; i < parentNode.childNodes.length ; i++ ) 
     560                        { 
     561                                var candidate = parentNode.childNodes[i] ; 
     562                                if ( normalized === true &&  
     563                                                candidate.nodeType == 3 &&  
     564                                                candidate.previousSibling &&  
     565                                                candidate.previousSibling.nodeType == 3 ) 
     566                                        continue; 
     567                                currentIndex++ ; 
     568                                if ( parentNode.childNodes[i] == node ) 
     569                                        break ; 
     570                        } 
     571                        retval.unshift( currentIndex ) ; 
    558572                        node = node.parentNode ; 
    559573                } 
     
    565579         * index address. 
    566580         */ 
    567         GetNodeFromAddress : function( doc, addr ) 
     581        GetNodeFromAddress : function( doc, addr, normalized ) 
    568582        { 
    569583                var cursor = doc.documentElement ; 
    570584                for ( var i = 0 ; i < addr.length ; i++ ) 
    571                         cursor = cursor.childNodes[ addr[i] ] ; 
     585                { 
     586                        var target = addr[i] ; 
     587                        if ( ! normalized ) 
     588                        { 
     589                                cursor = cursor.childNodes[target] ; 
     590                                continue ; 
     591                        } 
     592 
     593                        var currentIndex = -1 ; 
     594                        for (var j = 0 ; j < cursor.childNodes.length ; j++ ) 
     595                        { 
     596                                var candidate = cursor.childNodes[j] ; 
     597                                if ( normalized === true && 
     598                                                candidate.nodeType == 3 && 
     599                                                candidate.previousSibling && 
     600                                                candidate.previousSibling.nodeType == 3 ) 
     601                                        continue ; 
     602                                currentIndex++ ; 
     603                                if ( currentIndex == target ) 
     604                                { 
     605                                        cursor = candidate ; 
     606                                        break ; 
     607                                } 
     608                        } 
     609                } 
    572610                return cursor ; 
    573611        }, 
  • FCKeditor/trunk/editor/_source/internals/fckundo.js

    r936 r969  
    3131FCKUndo._GetBookmark = function() 
    3232{ 
    33         if ( ! FCKBrowserInfo.IsIE ) 
    34                 FCK.EditorDocument.body.normalize() ; 
    3533        var range = new FCKDomRange( FCK.EditorWindow ) ; 
    3634        try