Changeset 636

Show
Ignore:
Timestamp:
2007-08-08 05:58:43 (17 months ago)
Author:
martinkou
Message:

Fixed #1043 : Fixed the issue where selection position changes on the same snapshot are not saved by the undo system.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/_source/internals/fckundo.js

    r634 r636  
    7878} 
    7979 
     80FCKUndo._CompareCursors = function( cursor1, cursor2 ) 
     81{ 
     82        for ( var i = 0 ; i < Math.min( cursor1.length, cursor2.length ) ; i++ ) 
     83        { 
     84                if ( cursor1[i] < cursor2[i] ) 
     85                        return -1; 
     86                else if (cursor1[i] > cursor2[i] ) 
     87                        return 1; 
     88        } 
     89        if ( cursor1.length < cursor2.length ) 
     90                return -1; 
     91        else if (cursor1.length > cursor2.length ) 
     92                return 1; 
     93        return 0; 
     94} 
     95 
     96FCKUndo._CheckIsBookmarksEqual = function( bookmark1, bookmark2 ) 
     97{ 
     98        if ( FCKBrowserInfo.IsIE ) 
     99        { 
     100                var startOffset1 = bookmark1[1].search( bookmark1[0].StartId ) ; 
     101                var startOffset2 = bookmark2[1].search( bookmark2[0].StartId ) ; 
     102                var endOffset1 = bookmark1[1].search( bookmark1[0].EndId ) ; 
     103                var endOffset2 = bookmark2[1].search( bookmark2[0].EndId ) ; 
     104                return startOffset1 == startOffset2 && endOffset1 == endOffset2 ; 
     105        } 
     106        else 
     107        { 
     108                return this._CompareCursors( bookmark1.Start, bookmark2.Start ) == 0  
     109                        && this._CompareCursors( bookmark1.End, bookmark2.End ) == 0 ; 
     110        } 
     111} 
     112 
    80113FCKUndo.SaveUndoStep = function() 
    81114{ 
     
    90123        // Get the HTML content. 
    91124        var sHtml = FCK.EditorDocument.body.innerHTML ; 
     125        var bookmark = this._GetBookmark() ; 
    92126 
    93127        // Shrink the array to the current level. 
     
    95129 
    96130        // Cancel operation if the new step is identical to the previous one. 
    97         if ( this.CurrentIndex > 0 && sHtml == this.SavedData[ this.CurrentIndex ][0] ) 
     131        if ( this.CurrentIndex > 0  
     132                        && sHtml == this.SavedData[ this.CurrentIndex ][0]  
     133                        && this._CheckIsBookmarksEqual( bookmark, this.SavedData[ this.CurrentIndex ][1] ) ) 
    98134                return ; 
    99135        // Save the selection and caret position in the first undo level for the first change. 
    100136        else if ( this.CurrentIndex == 0 && this.SavedData.length && sHtml == this.SavedData[0][0] ) 
    101137        { 
    102                 this.SavedData[0][1] = this._GetBookmark() ; 
     138                this.SavedData[0][1] = bookmark ; 
    103139                return ; 
    104140        } 
     
    112148 
    113149        // Save the new level in front of the actual position. 
    114         this.SavedData[ this.CurrentIndex ] = [ sHtml, this._GetBookmark() ] ; 
     150        this.SavedData[ this.CurrentIndex ] = [ sHtml, bookmark ] ; 
    115151 
    116152        FCK.Events.FireEvent( "OnSelectionChange" ) ;