Reviewed by Chris
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Nov 2004 22:03:04 +0000 (22:03 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Nov 2004 22:03:04 +0000 (22:03 +0000)
        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::initializePositionData): Move position adjustments for
        smart delete from the two functions below to here. There was an unnecessary double
        calculation of the leading and trailing whitespace positions. Also refined the trailing
        case so it only acts when the leading position is null (which seems to match TextEdit in
        my tests). Also removed some unnecessary copying of Position objects.
        (khtml::DeleteSelectionCommand::startPositionForDelete): Move out smart delete adjustment
        from here.
        (khtml::DeleteSelectionCommand::endPositionForDelete): Ditto.

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

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

index 78711efb7dd3b49a42bc23ac2b9bc3f3d27fa604..3d633491ca22e8a1103d5a5960acd2c49fbe00fc 100644 (file)
@@ -1,3 +1,17 @@
+2004-11-10  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Chris
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::initializePositionData): Move position adjustments for
+        smart delete from the two functions below to here. There was an unnecessary double 
+        calculation of the leading and trailing whitespace positions. Also refined the trailing
+        case so it only acts when the leading position is null (which seems to match TextEdit in
+        my tests). Also removed some unnecessary copying of Position objects.
+        (khtml::DeleteSelectionCommand::startPositionForDelete): Move out smart delete adjustment
+        from here.
+        (khtml::DeleteSelectionCommand::endPositionForDelete): Ditto.
+
 2004-11-10  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Harrison
index d93d6bf0071b0d061b543c26c3455913db096025..24830fdd3dabeb622719f0481611a3fc786c9ab2 100644 (file)
@@ -1405,13 +1405,34 @@ void DeleteSelectionCommand::initializePositionData()
     Position start = startPositionForDelete();
     Position end = endPositionForDelete();
 
-    m_upstreamStart = Position(start.upstream(StayInBlock));
-    m_downstreamStart = Position(start.downstream(StayInBlock));
-    m_upstreamEnd = Position(end.upstream(StayInBlock));
-    m_downstreamEnd = Position(end.downstream(StayInBlock));
+    m_upstreamStart = start.upstream(StayInBlock);
+    m_downstreamStart = start.downstream(StayInBlock);
+    m_upstreamEnd = end.upstream(StayInBlock);
+    m_downstreamEnd = end.downstream(StayInBlock);
 
     m_leadingWhitespace = m_upstreamStart.leadingWhitespacePosition();
+    bool hasLeadingWhitespaceBeforeAdjustment = m_leadingWhitespace.isNotNull();
+    if (m_smartDelete && hasLeadingWhitespaceBeforeAdjustment) {
+        Position pos = VisiblePosition(start).previous().deepEquivalent();
+        // Expand out one character upstream for smart delete and recalculate
+        // positions based on this change.
+        m_upstreamStart = pos.upstream(StayInBlock);
+        m_downstreamStart = pos.downstream(StayInBlock);
+        m_leadingWhitespace = m_upstreamStart.leadingWhitespacePosition();
+    }
+
     m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition();
+    // Note: trailing whitespace is only considered for smart delete if there is no leading
+    // whitespace, as in the case where you double-click the first word of a paragraph.
+    if (m_smartDelete && !hasLeadingWhitespaceBeforeAdjustment && m_trailingWhitespace.isNotNull()) {
+        // Expand out one character downstream for smart delete and recalculate
+        // positions based on this change.
+        Position pos = VisiblePosition(end).next().deepEquivalent();
+        m_upstreamEnd = pos.upstream(StayInBlock);
+        m_downstreamEnd = pos.downstream(StayInBlock);
+        m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition();
+    }
+        
     m_trailingWhitespaceValid = true;
     
     debugPosition("m_upstreamStart      ", m_upstreamStart);
@@ -1439,8 +1460,6 @@ Position DeleteSelectionCommand::startPositionForDelete() const
     Position rootStart = Position(rootElement, 0);
     if (pos == VisiblePosition(rootStart).deepEquivalent())
         pos = rootStart;
-    else if (m_smartDelete && pos.leadingWhitespacePosition().isNotNull())
-        pos = VisiblePosition(pos).previous().deepEquivalent();
     return pos;
 }
 
@@ -1453,8 +1472,6 @@ Position DeleteSelectionCommand::endPositionForDelete() const
     Position rootEnd = Position(rootElement, rootElement ? rootElement->childNodeCount() : 0).equivalentDeepPosition();
     if (pos == VisiblePosition(rootEnd).deepEquivalent())
         pos = rootEnd;
-    else if (m_smartDelete && pos.trailingWhitespacePosition().isNotNull())
-        pos = VisiblePosition(pos).next().deepEquivalent();
     return pos;
 }