Reviewed by Ken Kocienda.
authorharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Nov 2004 03:46:04 +0000 (03:46 +0000)
committerharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Nov 2004 03:46:04 +0000 (03:46 +0000)
<rdar://problem/3865854> Deleting first line deletes all lines

        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::performGeneralDelete):
        Problem was that the code that deletes fully selected m_downstreamEnd.node() by deleting one
        of its ancestors, failed to end the loop that deletes all fully selected nodes.  Also,
        fixed this code to clear m_trailingWhitespaceValid.  Also removed dead m_endingPosition
        update because it is handled in calculateEndingPosition now.
        * layout-tests/editing/deleting/delete-3865854-fix-expected.txt: Added.
        * layout-tests/editing/deleting/delete-3865854-fix.html: Added.

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

LayoutTests/editing/deleting/delete-3865854-fix-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-3865854-fix.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp

diff --git a/LayoutTests/editing/deleting/delete-3865854-fix-expected.txt b/LayoutTests/editing/deleting/delete-3865854-fix-expected.txt
new file mode 100644 (file)
index 0000000..9c38404
--- /dev/null
@@ -0,0 +1,22 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x112 [border: (2px solid #FF0000)]
+        RenderBlock {DIV} at (14,14) size 756x28
+          RenderInline {B} at (0,0) size 36x28
+            RenderText {TEXT} at (0,0) size 36x28
+              text run at (0,0) width 36: "one"
+        RenderBlock {DIV} at (14,42) size 756x28
+          RenderInline {B} at (0,0) size 54x28
+            RenderText {TEXT} at (0,0) size 54x28
+              text run at (0,0) width 54: "three"
+        RenderBlock {DIV} at (14,70) size 756x28
+          RenderInline {I} at (0,0) size 40x28
+            RenderText {TEXT} at (0,0) size 40x28
+              text run at (0,0) width 40: "four"
+selection is CARET:
+start:      position 3 of child 1 {TEXT} of child 1 {B} of child 2 {DIV} of root {DIV}
+upstream:   position 3 of child 1 {TEXT} of child 1 {B} of child 2 {DIV} of root {DIV}
+downstream: position 3 of child 1 {TEXT} of child 1 {B} of child 2 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/deleting/delete-3865854-fix.html b/LayoutTests/editing/deleting/delete-3865854-fix.html
new file mode 100644 (file)
index 0000000..ea8886b
--- /dev/null
@@ -0,0 +1,38 @@
+<html> 
+<head>
+
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+</style>
+
+<script>
+
+function editingTest() {
+    for (i = 0; i < 3; i++)
+       execMoveSelectionForwardByCharacterCommand(); 
+    execExtendSelectionForwardByLineCommand(); 
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable='true'>
+<div id="root" class="editing">
+<div id="test"><b>one</b></div><div><i>two</i></div>
+<div><b>three</b></div><div><i>four</i></div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 6bd771e..430a19e 100644 (file)
@@ -1,3 +1,18 @@
+2004-11-08  David Harrison  <harrison@apple.com>
+
+        Reviewed by Ken Kocienda.
+
+               <rdar://problem/3865854> Deleting first line deletes all lines
+               
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::performGeneralDelete):
+        Problem was that the code that deletes fully selected m_downstreamEnd.node() by deleting one
+        of its ancestors, failed to end the loop that deletes all fully selected nodes.  Also,
+        fixed this code to clear m_trailingWhitespaceValid.  Also removed dead m_endingPosition
+        update because it is handled in calculateEndingPosition now.
+        * layout-tests/editing/deleting/delete-3865854-fix-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-3865854-fix.html: Added.
+
 2004-11-08  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Hyatt
index cb68c29..658fead 100644 (file)
@@ -1505,6 +1505,7 @@ bool DeleteSelectionCommand::canPerformSpecialCaseBRDelete()
 void DeleteSelectionCommand::performGeneralDelete()
 {
     int startOffset = m_upstreamStart.offset();
+
     if (startOffset >= m_startNode->caretMaxOffset()) {
         if (m_startNode->isTextNode()) {
             // Delete any insignificant text from this node.
@@ -1512,6 +1513,7 @@ void DeleteSelectionCommand::performGeneralDelete()
             if (text->length() > (unsigned)m_startNode->caretMaxOffset())
                 deleteTextFromNode(text, m_startNode->caretMaxOffset(), text->length() - m_startNode->caretMaxOffset());
         }
+        
         // shift the start node to the next
         NodeImpl *old = m_startNode;
         m_startNode = old->traverseNextNode();
@@ -1556,9 +1558,10 @@ void DeleteSelectionCommand::performGeneralDelete()
                 while (n && n->lastChild())
                     n = n->lastChild();
                 if (n == m_downstreamEnd.node() && m_downstreamEnd.offset() >= m_downstreamEnd.node()->caretMaxOffset()) {
-                    NodeImpl *nextNode = node->traverseNextSibling();
+                    // remove an ancestor of m_downstreamEnd.node(), and thus m_downstreamEnd.node() itself
                     removeFullySelectedNode(node);
-                    node = nextNode;
+                    m_trailingWhitespaceValid = false;
+                    node = 0;
                 } 
                 else {
                     node = node->traverseNextNode();
@@ -1581,8 +1584,6 @@ void DeleteSelectionCommand::performGeneralDelete()
                     m_trailingWhitespaceValid = false;
                 }
             }
-            if (!m_downstreamEnd.node()->inDocument() && m_downstreamEnd.node()->inDocument())
-                m_endingPosition = Position(m_downstreamEnd.node(), 0);
         }
     }
 }