Reviewed by Maciej
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 20 Mar 2005 16:26:24 +0000 (16:26 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 20 Mar 2005 16:26:24 +0000 (16:26 +0000)
        Fix for this bug:

        <rdar://problem/4059578> Entire list deleted, and caret disappears, when delete key hit at end of list

        The problem is that a new case in the delete code did not consider when the
        downstream end node of the selection might be an ancestor of the upstream start
        node. That is the case in this bug. The downstream end is the body element, and
        this line of code would delete all the children of the downstream end:
            removeChildrenInRangePreservingPosition(m_downstreamEnd.node(), 0,
                m_downstreamEnd.offset(), m_upstreamStart);

        The fix is to check for this "is ancestor" case, and do some tree logic to find
        the right offset of the downstream end node for the call to
        removeChildrenInRangePreservingPosition().

        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::handleGeneralDelete): Fixed as described.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8939 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp

index debe5439ba8c27094c9f1b7934468fc564b57c54..386be4040530a2098d5b5c887f1d40e5dfb57ee7 100644 (file)
@@ -1,3 +1,25 @@
+2005-03-20  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Maciej
+        
+        Fix for this bug:
+        
+        <rdar://problem/4059578> Entire list deleted, and caret disappears, when delete key hit at end of list
+
+        The problem is that a new case in the delete code did not consider when the
+        downstream end node of the selection might be an ancestor of the upstream start
+        node. That is the case in this bug. The downstream end is the body element, and
+        this line of code would delete all the children of the downstream end:
+            removeChildrenInRangePreservingPosition(m_downstreamEnd.node(), 0, 
+                m_downstreamEnd.offset(), m_upstreamStart);
+
+        The fix is to check for this "is ancestor" case, and do some tree logic to find
+        the right offset of the downstream end node for the call to
+        removeChildrenInRangePreservingPosition().
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::handleGeneralDelete): Fixed as described.
+
 2005-03-19  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Maciej
index c9ecb0c711c7041547d81d4191f9c74dc2a62aa1..e9e4e976c28fc5ce28f27286a2de15422ecdaa1d 100644 (file)
@@ -2898,8 +2898,16 @@ void DeleteSelectionCommand::handleGeneralDelete()
                         m_trailingWhitespaceValid = false;
                     }
                 } else {
-                    removeChildrenInRangePreservingPosition(m_downstreamEnd.node(), 0, m_downstreamEnd.offset(), m_upstreamStart);
-                    m_downstreamEnd = Position(m_downstreamEnd.node(), 0);
+                    int offset = 0;
+                    if (m_upstreamStart.node()->isAncestor(m_downstreamEnd.node())) {
+                        NodeImpl *n = m_upstreamStart.node();
+                        while (n && n->parentNode() != m_downstreamEnd.node())
+                            n = n->parentNode();
+                        if (n)
+                            offset = n->nodeIndex() + 1;
+                    }
+                    removeChildrenInRangePreservingPosition(m_downstreamEnd.node(), offset, m_downstreamEnd.offset(), m_upstreamStart);
+                    m_downstreamEnd = Position(m_downstreamEnd.node(), offset);
                 }
             }
         }