LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Aug 2007 00:29:36 +0000 (00:29 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Aug 2007 00:29:36 +0000 (00:29 +0000)
        Reviewed by Harrison.

        <rdar://problem/5378473> Undoing a deletion that is part of an open typing command fails to reinsert the caret

        * editing/undo/5378473.html: Added.
        * platform/mac/editing: Added.
        * platform/mac/editing/undo: Added.
        * platform/mac/editing/undo/5378473-expected.checksum: Added.
        * platform/mac/editing/undo/5378473-expected.png: Added.
        * platform/mac/editing/undo/5378473-expected.txt: Added.

WebCore:

        Reviewed by Harrison.

        <rdar://problem/5378473>
        REGRESSION: Undoing a deletion that is part of an open typing command fails to reinsert the caret

        We recently made Undo of a series of deletes select all of the
        characters that were deleted, not just the most recently deleted
        character.  But the code that did this set a new starting selection
        after every delete, even those that were part of an open typing
        command that started with character insertions or forward deletes,
        operations that when undone, remove the starting selection being
        set from the document.

        After this change we only set a new starting selection if the open typing
        command was opened by a backward delete. The new behavior matches TextEdit.
        We don't do something similar or forward deletes because TextEdit opens
        and closes a new typing command on forward delete (added a FIXME about this).

        * editing/TypingCommand.cpp:
        (WebCore::TypingCommand::TypingCommand): Initialize
        m_openedByBackwardDelete.
        (WebCore::TypingCommand::forwardDeleteKeyPressed): Added a FIXME about
        how in TextEdit, forward deletes open and close a new typing command.
        (WebCore::TypingCommand::doApply): Set m_openedByBackwardDelete
        appropriately.
        (WebCore::TypingCommand::deleteKeyPressed): Only set the starting
        selection if this delete is the first one in an open typing command
        or one in a series of deletes that opened the typing command.
        * editing/TypingCommand.h: Added m_openedByBackwardDelete.

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

LayoutTests/ChangeLog
LayoutTests/editing/undo/5378473.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/undo/5378473-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/editing/undo/5378473-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/editing/undo/5378473-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/editing/TypingCommand.cpp
WebCore/editing/TypingCommand.h

index 79088657ae6c31bc1064275429ef57454463b4d7..958ef1da244caf1f177f82e197c6e9a2a9f97763 100644 (file)
@@ -1,3 +1,16 @@
+2007-08-16  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Harrison.
+        
+        <rdar://problem/5378473> Undoing a deletion that is part of an open typing command fails to reinsert the caret
+
+        * editing/undo/5378473.html: Added.
+        * platform/mac/editing: Added.
+        * platform/mac/editing/undo: Added.
+        * platform/mac/editing/undo/5378473-expected.checksum: Added.
+        * platform/mac/editing/undo/5378473-expected.png: Added.
+        * platform/mac/editing/undo/5378473-expected.txt: Added.
+
 2007-08-16  Alice Liu  <alice.liu@apple.com>
 
         Removed a fixed test from the skip list.  r25112 fixed this test.
diff --git a/LayoutTests/editing/undo/5378473.html b/LayoutTests/editing/undo/5378473.html
new file mode 100644 (file)
index 0000000..4833b50
--- /dev/null
@@ -0,0 +1,9 @@
+<div id="div" contenteditable="true"></div>
+
+<script>
+div = document.getElementById("div");
+div.focus();
+document.execCommand("InsertText", false, "foo");
+document.execCommand("Delete");
+document.execCommand("Undo");
+</script>
diff --git a/LayoutTests/platform/mac/editing/undo/5378473-expected.checksum b/LayoutTests/platform/mac/editing/undo/5378473-expected.checksum
new file mode 100644 (file)
index 0000000..b09182d
--- /dev/null
@@ -0,0 +1 @@
+2a251ca75a4ee28206fbc9f203a921e3
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/editing/undo/5378473-expected.png b/LayoutTests/platform/mac/editing/undo/5378473-expected.png
new file mode 100644 (file)
index 0000000..f5e50a3
Binary files /dev/null and b/LayoutTests/platform/mac/editing/undo/5378473-expected.png differ
diff --git a/LayoutTests/platform/mac/editing/undo/5378473-expected.txt b/LayoutTests/platform/mac/editing/undo/5378473-expected.txt
new file mode 100644 (file)
index 0000000..a5c5a94
--- /dev/null
@@ -0,0 +1,7 @@
+layer at (0,0) size 800x600
+  RenderView 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 784x18
+caret: position 0 of child 0 {DIV} of child 0 {BODY} of child 0 {HTML} of document
index d198a671adf14bee4df0338a67404871b6c88560..34cfc908493a1a3cb666a79a46a9d1775a9230df 100644 (file)
@@ -1,3 +1,35 @@
+2007-08-16  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Harrison.
+
+        <rdar://problem/5378473> 
+        REGRESSION: Undoing a deletion that is part of an open typing command fails to reinsert the caret
+        
+        We recently made Undo of a series of deletes select all of the 
+        characters that were deleted, not just the most recently deleted
+        character.  But the code that did this set a new starting selection 
+        after every delete, even those that were part of an open typing 
+        command that started with character insertions or forward deletes, 
+        operations that when undone, remove the starting selection being 
+        set from the document.
+        
+        After this change we only set a new starting selection if the open typing
+        command was opened by a backward delete. The new behavior matches TextEdit.  
+        We don't do something similar or forward deletes because TextEdit opens 
+        and closes a new typing command on forward delete (added a FIXME about this).
+
+        * editing/TypingCommand.cpp:
+        (WebCore::TypingCommand::TypingCommand): Initialize 
+        m_openedByBackwardDelete.
+        (WebCore::TypingCommand::forwardDeleteKeyPressed): Added a FIXME about
+        how in TextEdit, forward deletes open and close a new typing command.
+        (WebCore::TypingCommand::doApply): Set m_openedByBackwardDelete
+        appropriately.
+        (WebCore::TypingCommand::deleteKeyPressed): Only set the starting
+        selection if this delete is the first one in an open typing command
+        or one in a series of deletes that opened the typing command.
+        * editing/TypingCommand.h: Added m_openedByBackwardDelete.
+
 2007-08-13  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Dave Hyatt.
index eeaf101352327f9b6497a10279a63639c81a4416..106d70cd68a48da15904fc95ecab2803d3526d27 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index d9dbaa1953042aa6f6c5c20e184b28ca77fea762..748db9be35b35b7667ff1a8347db51785d86bcf5 100644 (file)
@@ -51,7 +51,8 @@ TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, con
       m_applyEditing(false), 
       m_selectInsertedText(selectInsertedText),
       m_smartDelete(false),
-      m_granularity(granularity)
+      m_granularity(granularity),
+      m_openedByBackwardDelete(false)
 {
 }
 
@@ -75,6 +76,7 @@ void TypingCommand::deleteKeyPressed(Document *document, bool smartDelete, TextG
 
 void TypingCommand::forwardDeleteKeyPressed(Document *document, bool smartDelete, TextGranularity granularity)
 {
+    // FIXME: Forward delete in TextEdit appears to open and close a new typing command.
     ASSERT(document);
     
     Frame *frame = document->frame();
@@ -218,6 +220,10 @@ void TypingCommand::doApply()
 {
     if (endingSelection().isNone())
         return;
+        
+    if (m_commandType == DeleteKey)
+        if (m_commands.isEmpty())
+            m_openedByBackwardDelete = true;
 
     switch (m_commandType) {
         case DeleteKey:
@@ -391,8 +397,11 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity)
     }
     
     if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(selectionToDelete)) {
-        // make undo select what was deleted
-        setStartingSelection(selectionAfterUndo);
+        // Make undo select everything that has been deleted, unless an undo will undo more than just this deletion.
+        // FIXME: This behaves like TextEdit except for the case where you open with text insertion and then delete
+        // more text than you insert.  In that case all of the text that was around originally should be selected.
+        if (m_openedByBackwardDelete)
+            setStartingSelection(selectionAfterUndo);
         deleteSelection(selectionToDelete, m_smartDelete);
         setSmartDelete(false);
         typingAddedToOpenCommand();
index 051f50e59856fba29b7403485b608bebe0830487..49e67bc1fa7f45312551d40fcd21a4d2df054b5c 100644 (file)
@@ -84,6 +84,11 @@ private:
     bool m_selectInsertedText;
     bool m_smartDelete;
     TextGranularity m_granularity;
+    
+    // Undoing a series of backward deletes will restore a selection around all of the
+    // characters that were deleted, but only if the typing command being undone
+    // was opened with a backward delete.
+    bool m_openedByBackwardDelete;
 };
 
 } // namespace WebCore