Reviewed by Maciej
[WebKit-https.git] / WebCore / khtml / editing / htmlediting.cpp
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);
                 }
             }
         }