Changeset 630

Show
Ignore:
Timestamp:
2007-08-07 08:08:52 (17 months ago)
Author:
martinkou
Message:

Fixed the issue where FCKSelection.GetParentElement() returns different values for large selections in Gecko compaerd to IE.
Fixed the issue where FCKSelection sometimes ignores collapsed text selections in IE.

Location:
FCKeditor/trunk/editor/_source/internals
Files:
2 modified

Legend:

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

    r480 r630  
    6666                if ( oSel ) 
    6767                { 
    68                         var oNode = oSel.anchorNode ; 
    69  
    70                         while ( oNode && oNode.nodeType != 1 ) 
    71                                 oNode = oNode.parentNode ; 
    72  
    73                         return oNode ; 
     68                        // make the common case fast - for collapsed/nearly collapsed selections just return anchor.parent. 
     69                        if ( oSel.anchorNode == oSel.focusNode ) 
     70                                return oSel.anchorNode.parentNode ; 
     71 
     72                        // looks like we're having a large selection here. To make the behavior same as IE's TextRange.parentElement(), 
     73                        // we need to find the nearest ancestor node which encapsulates both the beginning and the end of the selection. 
     74                        var anchorPath = new FCKElementPath( oSel.anchorNode ) ; 
     75                        var focusPath = new FCKElementPath( oSel.focusNode ) ;  
     76                        var deepPath = null ; 
     77                        var shallowPath = null ; 
     78                        if ( anchorPath.Elements.length > focusPath.Elements.length ) 
     79                        { 
     80                                deepPath = anchorPath.Elements ; 
     81                                shallowPath = focusPath.Elements ; 
     82                        } 
     83                        else 
     84                        { 
     85                                deepPath = focusPath.Elements ; 
     86                                shallowPath = anchorPath.Elements ; 
     87                        } 
     88                         
     89                        var deepPathBase = deepPath.length - shallowPath.length ; 
     90                        for( var i = 0 ; i < shallowPath.length ; i++) 
     91                        { 
     92                                if ( deepPath[deepPathBase + i] == shallowPath[i]) 
     93                                        return shallowPath[i]; 
     94                        } 
     95                        return null ; 
    7496                } 
    7597        } 
  • FCKeditor/trunk/editor/_source/internals/fckselection_ie.js

    r495 r630  
    2525FCKSelection.GetType = function() 
    2626{ 
    27         return FCK.EditorDocument.selection.type ; 
     27        var ieType = FCK.EditorDocument.selection.type ; 
     28        if ( ieType == 'Control' || ieType == 'Text' ) 
     29                return ieType ; 
     30 
     31        // It is possible that we can still get a text range object even when type=='None' is returned by IE. 
     32        // So we'd better check the object returned by createRange() rather than by looking at the type. 
     33        if ( FCK.EditorDocument.selection.createRange().parentElement ) 
     34                return 'Text' ; 
     35        else 
     36                return 'None' ; 
    2837} ; 
    2938