Reviewed by Richard
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Sep 2004 22:03:25 +0000 (22:03 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Sep 2004 22:03:25 +0000 (22:03 +0000)
        Fix for this bug:

        <rdar://problem/3800834> REGRESSION (Mail): Can't delete backwards past quoted text using HTML editing

        * khtml/editing/htmlediting_impl.cpp:
        (khtml::TypingCommandImpl::issueCommandForDeleteKey): Use CaretPosition class to get superior
        smarts about the selection to delete in the "start of block" case. This fixes the bug.
        While I was in the neighborhood, I cleaned up this function a bit.
        * layout-tests/editing/deleting/delete-3800834-fix-expected.txt: Added.
        * layout-tests/editing/deleting/delete-3800834-fix.html: Added.

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

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

diff --git a/LayoutTests/editing/deleting/delete-3800834-fix-expected.txt b/LayoutTests/editing/deleting/delete-3800834-fix-expected.txt
new file mode 100644 (file)
index 0000000..8cc4f31
--- /dev/null
@@ -0,0 +1,18 @@
+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 784x56 [border: (2px solid #FF0000)]
+        RenderBlock (anonymous) at (14,14) size 756x28
+          RenderInline {SPAN} at (0,0) size 37x28
+            RenderText {TEXT} at (0,0) size 37x28
+              text run at (0,0) width 37: "Foo"
+        RenderBlock (anonymous) at (14,42) size 756x0
+        RenderBlock (anonymous) at (14,42) size 756x0
+          RenderInline {SPAN} at (0,0) size 0x0
+          RenderText {TEXT} at (0,0) size 0x0
+selection is CARET:
+start:      position 3 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
+upstream:   position 3 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
+downstream: position 1 of child 3 {TEXT} of root {DIV}
diff --git a/LayoutTests/editing/deleting/delete-3800834-fix.html b/LayoutTests/editing/deleting/delete-3800834-fix.html
new file mode 100644 (file)
index 0000000..6584b24
--- /dev/null
@@ -0,0 +1,37 @@
+<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 (var i = 0; i < 8; i++)
+        moveSelectionForwardByCharacterCommand(); 
+    for (var i = 0; i < 4; i++)
+        deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable='true'>
+<div id="root" class="editing">
+<span id="test">Foo<BR><BLOCKQUOTE>Bar</BLOCKQUOTE></span>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 5ae0daf70cac60810175094aeb0e140379121070..dbf8191e4eb9252ecdb7e2df411c7ca39b98a9c7 100644 (file)
@@ -1,3 +1,18 @@
+2004-09-14  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Richard
+
+        Fix for this bug:
+        
+        <rdar://problem/3800834> REGRESSION (Mail): Can't delete backwards past quoted text using HTML editing
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::TypingCommandImpl::issueCommandForDeleteKey): Use CaretPosition class to get superior
+        smarts about the selection to delete in the "start of block" case. This fixes the bug.
+        While I was in the neighborhood, I cleaned up this function a bit.
+        * layout-tests/editing/deleting/delete-3800834-fix-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-3800834-fix.html: Added.
+
 2004-09-14  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by me
index 271c1bbb96f28e0f2803a4c4b5c4c8b978482299..5036f7930d0ee78c4e70d03eb30906cc8ae4334e 100644 (file)
@@ -2301,22 +2301,32 @@ void TypingCommandImpl::insertNewline()
 
 void TypingCommandImpl::issueCommandForDeleteKey()
 {
-    Selection selectionToDelete = endingSelection();
-    ASSERT(selectionToDelete.state() != Selection::NONE);
+    Selection selectionToDelete;
     
-    if (selectionToDelete.state() == Selection::CARET) {
-        Position pos(selectionToDelete.start());
-        if (pos.inFirstEditableInRootEditableElement() && pos.offset() <= pos.node()->caretMinOffset()) {
-            // we're at the start of a root editable block...do nothing
-            return;
+    switch (endingSelection().state()) {
+        case Selection::RANGE:
+            selectionToDelete = endingSelection();
+            break;
+        case Selection::CARET: {
+            // Handle delete at beginning-of-block case.
+            // Do nothing in the case that the caret is at the start of a
+            // root editable element or at the start of a document.
+            Position pos(endingSelection().start());
+            Position start = CaretPosition(pos).previous().deepEquivalent();
+            Position end = CaretPosition(pos).deepEquivalent();
+            if (start.notEmpty() && end.notEmpty() && start.node()->rootEditableElement() == end.node()->rootEditableElement())
+                selectionToDelete = Selection(start, end);
+            break;
         }
-        if (pos.inRenderedContent())
-            selectionToDelete = Selection(pos.previousCharacterPosition(), pos);
-        else
-            selectionToDelete = Selection(pos.upstream(StayInBlock).previousCharacterPosition(), pos.downstream());
+        case Selection::NONE:
+            ASSERT_NOT_REACHED();
+            break;
+    }
+    
+    if (selectionToDelete.notEmpty()) {
+        deleteSelection(selectionToDelete);
+        typingAddedToOpenCommand();
     }
-    deleteSelection(selectionToDelete);
-    typingAddedToOpenCommand();
 }
 
 void TypingCommandImpl::deleteKeyPressed()