2010-03-03 Ojan Vafai <ojan@chromium.org>
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Mar 2010 23:41:38 +0000 (23:41 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Mar 2010 23:41:38 +0000 (23:41 +0000)
        Reviewed by Adam Barth.

        undo after smartdelete should select the deleted space
        https://bugs.webkit.org/show_bug.cgi?id=35713

        * editing/undo/undo-smart-delete-reversed-selection-expected.txt: Added.
        * editing/undo/undo-smart-delete-reversed-selection.html: Added.
        * editing/undo/undo-smart-delete-word-expected.txt: Added.
        * editing/undo/undo-smart-delete-word.html: Added.
2010-03-03  Ojan Vafai  <ojan@chromium.org>

        Reviewed by Adam Barth.

        undo after smartdelete should select the deleted space
        https://bugs.webkit.org/show_bug.cgi?id=35713

        TextEdit behavior is to select the deleted space after a smartdelete.

        Tests: editing/undo/undo-smart-delete-reversed-selection.html
               editing/undo/undo-smart-delete-word.html

        * editing/DeleteSelectionCommand.cpp:
        (WebCore::DeleteSelectionCommand::setStartingSelectionOnSmartDelete):
        (WebCore::DeleteSelectionCommand::initializePositionData):
        * editing/DeleteSelectionCommand.h:
        * editing/VisibleSelection.cpp:
        (WebCore::VisibleSelection::setWithoutValidation):
        This assert looks bogus to me. undo-smart-delete-reversed-selection.html hits it
        but not as a result of the other changes in this patch. The granularity when
        deleting after making a wordgranularity selection is wordgranularity, not charactergranularity.

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

LayoutTests/ChangeLog
LayoutTests/editing/undo/undo-smart-delete-reversed-selection-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo/undo-smart-delete-reversed-selection.html [new file with mode: 0644]
LayoutTests/editing/undo/undo-smart-delete-word-expected.txt [new file with mode: 0644]
LayoutTests/editing/undo/undo-smart-delete-word.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/DeleteSelectionCommand.cpp
WebCore/editing/DeleteSelectionCommand.h
WebCore/editing/VisibleSelection.cpp

index 374d593..072a084 100644 (file)
@@ -1,3 +1,15 @@
+2010-03-03  Ojan Vafai  <ojan@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        undo after smartdelete should select the deleted space
+        https://bugs.webkit.org/show_bug.cgi?id=35713
+
+        * editing/undo/undo-smart-delete-reversed-selection-expected.txt: Added.
+        * editing/undo/undo-smart-delete-reversed-selection.html: Added.
+        * editing/undo/undo-smart-delete-word-expected.txt: Added.
+        * editing/undo/undo-smart-delete-word.html: Added.
+
 2010-03-09  Anton Muhin  <antonm@chromium.org>
 
         Reviewed by Darin Fisher.
diff --git a/LayoutTests/editing/undo/undo-smart-delete-reversed-selection-expected.txt b/LayoutTests/editing/undo/undo-smart-delete-reversed-selection-expected.txt
new file mode 100644 (file)
index 0000000..0dc77db
--- /dev/null
@@ -0,0 +1,5 @@
+Tests: 
+Double-click the green "a" and drag backwards to select "bar baz" with word granularity. Delete, then undo the delete. The space that got smart deleted should now be selected and the anchor of the selection should be at the end of the selection.
+
+foo bar baz biz
+PASSED
diff --git a/LayoutTests/editing/undo/undo-smart-delete-reversed-selection.html b/LayoutTests/editing/undo/undo-smart-delete-reversed-selection.html
new file mode 100644 (file)
index 0000000..217bbfb
--- /dev/null
@@ -0,0 +1,70 @@
+<html>
+<head>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function getStringForNode(node) {
+    return node + "(" + node.data + ")";
+}
+
+function editingTest() {
+    var start = document.getElementById("start");
+    var x = start.offsetLeft + 5;
+    var middleY = start.offsetTop + start.offsetHeight / 2;
+    var endX = document.getElementById("end").offsetLeft;
+
+    eventSender.mouseMoveTo(x, middleY);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+    eventSender.mouseDown();
+
+    eventSender.mouseMoveTo(endX, middleY);
+    eventSender.mouseUp();
+
+    document.execCommand("Delete");
+    document.execCommand("Undo");
+    
+    var selection = window.getSelection();
+    if (selection.anchorNode != start.nextSibling ||
+        selection.anchorOffset != 1 ||
+        selection.focusNode != document.getElementById("root").firstChild ||
+        selection.focusOffset != 4) {
+        document.getElementById("result").innerHTML = "FAILED. Selection was " +
+          "anchorNode:" + getStringForNode(selection.anchorNode) +
+          " anchorOffset:" + selection.anchorOffset +
+          " focusNode:" + getStringForNode(selection.focusNode) +
+          " focusOffset:" + selection.focusOffset;
+    } else
+        document.getElementById("result").innerHTML = "PASSED";
+}
+
+</script>
+</head> 
+<body>
+
+<div class="explanation">
+<div class="scenario">
+Tests: 
+<br>
+Double-click the green "a" and drag backwards to select "bar baz" with word granularity. Delete, then undo the delete. The space that got smart deleted should now be selected and the anchor of the selection should be at the end of the selection.
+</div>
+</div>
+<br>
+<div contenteditable id="root">
+foo b<span id="end">a</span>r b<span id="start" style="color:green">a</span>z biz
+</div>
+
+<div id="result"></div>
+<script>
+layoutTestController.waitUntilDone();
+setTimeout(function() {
+    editingTest();
+    layoutTestController.notifyDone();
+}, 1000);
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/undo/undo-smart-delete-word-expected.txt b/LayoutTests/editing/undo/undo-smart-delete-word-expected.txt
new file mode 100644 (file)
index 0000000..8b6a733
--- /dev/null
@@ -0,0 +1,4 @@
+Tests: 
+Select a word via double-click. Delete. Then undo the delete. The space that got smart deleted should now be selected.
+foo bar baz
+PASSED
diff --git a/LayoutTests/editing/undo/undo-smart-delete-word.html b/LayoutTests/editing/undo/undo-smart-delete-word.html
new file mode 100644 (file)
index 0000000..1e2feb1
--- /dev/null
@@ -0,0 +1,58 @@
+<html>
+<head>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function editingTest() {
+    var word = document.getElementById("word");
+    var x = word.offsetLeft;
+    var y = word.offsetTop;
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+
+    document.execCommand("Delete");
+    document.execCommand("Undo");
+    
+    var selection = window.getSelection();
+    if (selection.anchorNode != document.getElementById("root").firstChild ||
+        selection.anchorOffset != 4 ||
+        selection.focusNode != word.firstChild ||
+        selection.focusOffset != 3) {
+        document.getElementById("result").innerHTML = "FAILED";
+        console.log(selection.anchorNode);
+        console.log(selection.anchorOffset);
+        console.log(selection.focusNode);
+        console.log(selection.focusOffset);        
+    } else
+        document.getElementById("result").innerHTML = "PASSED";
+}
+
+</script>
+</head> 
+<body>
+
+<div class="explanation">
+<div class="scenario">
+Tests: 
+<br>
+Select a word via double-click. Delete. Then undo the delete. The space that got smart deleted should now be selected.
+</div>
+</div>
+
+<div contenteditable id="root">
+foo <span id="word">bar</span> baz
+</div>
+
+<div id="result"></div>
+<script>
+editingTest();
+</script>
+
+</body>
+</html>
index 98e4193..9e1f717 100644 (file)
@@ -1,3 +1,25 @@
+2010-03-03  Ojan Vafai  <ojan@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        undo after smartdelete should select the deleted space
+        https://bugs.webkit.org/show_bug.cgi?id=35713
+
+        TextEdit behavior is to select the deleted space after a smartdelete.
+
+        Tests: editing/undo/undo-smart-delete-reversed-selection.html
+               editing/undo/undo-smart-delete-word.html
+
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::setStartingSelectionOnSmartDelete):
+        (WebCore::DeleteSelectionCommand::initializePositionData):
+        * editing/DeleteSelectionCommand.h:
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::setWithoutValidation):
+        This assert looks bogus to me. undo-smart-delete-reversed-selection.html hits it
+        but not as a result of the other changes in this patch. The granularity when
+        deleting after making a wordgranularity selection is wordgranularity, not charactergranularity.
+
 2010-03-09  Steve Falkenburg  <sfalken@apple.com>
 
         Rubber stamped by Adam Roben.
index d3d9cc9..8027b14 100644 (file)
@@ -161,6 +161,20 @@ void DeleteSelectionCommand::initializeStartEnd(Position& start, Position& end)
     }
 }
 
+void DeleteSelectionCommand::setStartingSelectionOnSmartDelete(Position& start, Position& end)
+{
+    VisiblePosition newBase;
+    VisiblePosition newExtent;
+    if (startingSelection().isBaseFirst()) {
+        newBase = start;
+        newExtent = end;
+    } else {
+        newBase = end;
+        newExtent = start;        
+    }
+    setStartingSelection(VisibleSelection(newBase, newExtent));            
+}
+    
 void DeleteSelectionCommand::initializePositionData()
 {
     Position start, end;
@@ -230,6 +244,8 @@ void DeleteSelectionCommand::initializePositionData()
             m_upstreamStart = pos.upstream();
             m_downstreamStart = pos.downstream();
             m_leadingWhitespace = m_upstreamStart.leadingWhitespacePosition(visiblePos.affinity());
+
+            setStartingSelectionOnSmartDelete(m_upstreamStart, m_upstreamEnd);
         }
         
         // trailing whitespace is only considered for smart delete if there is no leading
@@ -241,6 +257,8 @@ void DeleteSelectionCommand::initializePositionData()
             m_upstreamEnd = pos.upstream();
             m_downstreamEnd = pos.downstream();
             m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition(VP_DEFAULT_AFFINITY);
+
+            setStartingSelectionOnSmartDelete(m_downstreamStart, m_downstreamEnd);
         }
     }
     
index c8872ef..44a005c 100644 (file)
@@ -51,6 +51,7 @@ private:
     virtual bool preservesTypingStyle() const;
 
     void initializeStartEnd(Position&, Position&);
+    void setStartingSelectionOnSmartDelete(Position&, Position&);
     void initializePositionData();
     void saveTypingStyleState();
     void insertPlaceholderForAncestorBlockContent();
index baef2b5..571fe2b 100644 (file)
@@ -441,7 +441,6 @@ void VisibleSelection::setWithoutValidation(const Position& base, const Position
     ASSERT(!extent.isNull());
     ASSERT(base != extent);
     ASSERT(m_affinity == DOWNSTREAM);
-    ASSERT(m_granularity == CharacterGranularity);
     m_base = base;
     m_extent = extent;
     m_baseIsFirst = comparePositions(base, extent) <= 0;