Changeset 1164


Ignore:
Timestamp:
02/12/09 21:57:13 (11 years ago)
Author:
douglas
Message:

FIXED moveCursor on line misunderstood offsets, as did splitTree...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Ticket1226/paraHandlerBest.js

    r1162 r1164  
    959959 
    960960    var insertNode = breaker; 
     961    // XXX TODO don't use a closure to access this, pass it in... 
    961962    for (;recreateStack.length>0;) 
    962963    { 
     
    967968    } 
    968969 
    969     var innermostNode = insertNode; 
     970    // We need to keep track of the new cursor location.  When our cursor is in 
     971    // the middle of a text node, the new cursor will be at the beginning of 
     972    // the text node we create to contain the text to the right of the cursor. 
     973    // Otherwise, the cursor will point to a node, and the new cursor needs to 
     974    // point to that node in it's new location. 
     975    var newCursorNode = null; 
    970976 
    971977    var sourceNode = splitNode; 
     978    var sourceOffset = splitOffset; 
    972979    if (TEXT_NODE == sourceNode.nodeType) 
    973980    { 
    974981      var textNode = doc.createTextNode(sourceNode.nodeValue.substring(splitOffset,sourceNode.nodeValue.length)); 
    975       innermostNode = textNode = insertNode.appendChild(textNode); 
     982      newCursorNode = textNode = insertNode.appendChild(textNode); 
    976983      sourceNode.nodeValue = sourceNode.nodeValue.substring(0,splitOffset); 
    977984    } 
     
    983990    // position on the newly duplicated tree. 
    984991 
    985     // Move insertNode from the inside outwards towards the root, moving any content nodes as we go. 
     992    // Move insertNode from the inside outwards towards the root, moving any content nodes as we go.  We'll make sure that we can do the same with sourceNode 
    986993    while (insertNode != root.parentNode) 
    987994    { 
    988       for (var moveNode=sourceNode.nextSibling;moveNode;) 
     995      for (var moveNode=sourceNode.childNodes[sourceOffset];moveNode;) 
    989996      { 
    990997        // We have to take a reference to the next sibling before cutting out 
     
    9991006 
    10001007      // Move both of our node pointers one step closer to the root node. 
     1008      sourceOffset = EnterParagraphs.prototype.indexInParent(sourceNode); 
    10011009      sourceNode = sourceNode.parentNode; 
    10021010      insertNode = insertNode.parentNode; 
     
    10601068    } 
    10611069 
     1070    // If the cursor node wasn't created by the split (it was moved), then that 
     1071    // means we need to point to the inside of our brand new tree. 
     1072    if (!newCursorNode) 
     1073    { 
     1074      newCursorNode = breaker.childNodes[0]; 
     1075    } 
     1076 
    10621077    // Make sure when we split the tree that we don't leave any empty nodes, as 
    10631078    // that would have visual glitches. 
    10641079    stuffEmptyNode(splitNode, doc); 
    1065     stuffEmptyNode(innermostNode, doc); 
     1080    stuffEmptyNode(newCursorNode, doc); 
    10661081 
    10671082    // So that we can correctly set the selection, we'll return a reference to 
    10681083    // the inserted subtree. 
    1069     return innermostNode; 
     1084    return newCursorNode; 
    10701085  } 
    10711086  function insertLineBreak(cursorParent, cursorOffset, useNewline, doc) 
     
    15111526 
    15121527    // If we are no longer inside of one of our trigger nodes, we're done. 
    1513     if (!this._pifyParent.test(cursorParent.parentNode.nodeName) && 
    1514         !this._pifySibling.test(cursorParent.parentNode.nodeName)) 
     1528    if (!this._pifyParent.test(cursorParent.nodeName) && 
     1529        !this._pifySibling.test(cursorParent.nodeName)) 
    15151530    { 
    15161531      // Move the real cursor. 
     
    15531568 
    15541569    // If we are no longer inside of one of our trigger nodes, we're done. 
    1555     if (!this._pifyParent.test(cursorParent.parentNode.nodeName) && 
    1556         !this._pifySibling.test(cursorParent.parentNode.nodeName)) 
     1570    if (!this._pifyParent.test(cursorParent.nodeName) && 
     1571        !this._pifySibling.test(cursorParent.nodeName)) 
    15571572    { 
    15581573      // Move the real cursor. 
Note: See TracChangeset for help on using the changeset viewer.