Changeset 596

Show
Ignore:
Timestamp:
2007-07-31 05:59:58 (16 months ago)
Author:
martinkou
Message:

Fixed #393 : Fixed the issue where, in Gecko, inline tags would keep expanding with character key presses when the caret is already at the end of the inline tag.

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

Legend:

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

    r590 r596  
    5959        } 
    6060 
     61        this._ExecCheckCaret = function( evt ) 
     62        { 
     63                if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) 
     64                        return ; 
     65 
     66                var keyCode = evt.keyCode ; 
     67                var modKeys = { 34 : 1, 35 : 1, 39 : 1, 40 : 1 } ; 
     68                if ( ! modKeys[keyCode] ) 
     69                        return ; 
     70 
     71                var moveCursor = function() 
     72                { 
     73                        var selection = FCK.EditorWindow.getSelection() ; 
     74                        var range = selection.getRangeAt(0) ; 
     75                        if ( ! range || ! range.collapsed ) 
     76                                return ; 
     77 
     78                        var node = range.endContainer ; 
     79                         
     80                        if ( node.nodeType != 3 ) 
     81                                return ; 
     82 
     83                        if ( node.nodeValue.length != range.endOffset ) 
     84                                return ; 
     85 
     86                        // we've moved to just after the last character of a text node under an unknown tag, how to proceed? 
     87                        // first, see if there are other text nodes by DFS walking from this text node. 
     88                        //      - if the DFS has scanned all nodes under my parent, then go the next step. 
     89                        //      - if there is a text node after me but still under my parent, then do nothing and return. 
     90                        var nextTextNode = FCKTools.GetNextTextNode( node, node.parentNode ) ; 
     91                        if ( nextTextNode ) 
     92                                return ; 
     93 
     94                        // we're pretty sure we need to move the caret forcefully from here. 
     95                        range = FCK.EditorDocument.createRange() ; 
     96 
     97                        nextTextNode = FCKTools.GetNextTextNode( node, node.parentNode.parentNode ) ; 
     98                        if ( nextTextNode ) 
     99                        { 
     100                                // now we want to get out of our current parent node, adopt the next parent, and move the caret to  
     101                                // the appropriate text node under our new parent. 
     102                                // our new parent might be our curernt parent's siblings if we are lucky. 
     103                                range.setStart( nextTextNode, 0 ) ; 
     104                                range.setEnd( nextTextNode, 0 ) ; 
     105                        } 
     106                        else 
     107                        { 
     108                                // no suitable next siblings under our grandparent! what to do next? 
     109                                node = node.parentNode ; 
     110                                if ( FCKListsLib.BlockElements[ node.tagName.toLowerCase() ] || node == FCK.EditorDocument.body ) 
     111                                { 
     112                                        // if our parent is a block node, move to the end of our parent. 
     113                                        range.setStart( node, node.childNodes.length ) ; 
     114                                        range.setEnd( node, node.childNodes.length ) ; 
     115                                } 
     116                                else 
     117                                { 
     118                                        // if our parent is not a block node, move to the end of our grandparent. 
     119                                        // note that the dummy marker below is NEEDED, otherwise the caret's behavior will  
     120                                        // be broken in Gecko. 
     121                                        var marker = FCK.EditorDocument.createTextNode( "" ) ; 
     122                                        node.parentNode.appendChild( marker ) ; 
     123                                        range.setStart( marker, 0 ) ; 
     124                                        range.setEnd( marker, 0 ) ; 
     125                                } 
     126                        } 
     127 
     128                        selection.removeAllRanges() ; 
     129                        selection.addRange( range ) ; 
     130                } 
     131                 
     132                setTimeout( moveCursor, 1 ) ; 
     133        } 
     134 
    61135        this.ExecOnSelectionChangeTimer = function() 
    62136        { 
     
    96170                this.EditorDocument.addEventListener( 'drop', this._ExecDrop, true ) ; 
    97171        } 
     172 
     173        // Kludge for buggy Gecko caret positioning logic (Bug #393) 
     174        if ( FCKBrowserInfo.IsGecko ) 
     175                this.EditorDocument.addEventListener( 'keypress', this._ExecCheckCaret, false ) ; 
    98176 
    99177        // Reset the context menu. 
  • FCKeditor/trunk/editor/_source/internals/fcktools.js

    r568 r596  
    511511        } 
    512512} 
     513 
     514// Perform a one-step DFS walk. 
     515FCKTools.GetNextNode = function( node, limitNode ) 
     516{ 
     517        if ( node.firstChild ) 
     518                return node.firstChild ; 
     519        else if ( node.nextSibling ) 
     520                return node.nextSibling ; 
     521        else 
     522        { 
     523                var ancestor = node.parentNode ; 
     524                while ( ancestor ) 
     525                { 
     526                        if ( ancestor == limitNode ) 
     527                                return null ; 
     528                        if ( ancestor.nextSibling ) 
     529                                return ancestor.nextSibling ; 
     530                        else 
     531                                ancestor = ancestor.parentNode ; 
     532                } 
     533        } 
     534        return null ; 
     535} 
     536 
     537FCKTools.GetNextTextNode = function( textnode, limitNode ) 
     538{ 
     539        node = this.GetNextNode( textnode, limitNode ) ; 
     540        while ( node && node.nodeType != 3 ) 
     541                node = this.GetNextNode( node, limitNode ) ; 
     542        return node ; 
     543}