| | 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 | |