Fixed: <rdar://problem/4030669> smart delete does not delete spaces from pasted...
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Mar 2005 23:26:37 +0000 (23:26 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Mar 2005 23:26:37 +0000 (23:26 +0000)
        Reviewed by rjw.

        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::initializePositionData): pass true for treatNBSPAsWhiteSpace to leadingWhitespacePosition and trailingWhitespacePosition when testing whether or not we have to delete those characters as well.
        * khtml/editing/jsediting.cpp: pass true for smartDelete when the selection granularity is WORD. This allows us to write smart delete layout tests.
        * layout-tests/editing/deleting/smart-delete-001-expected.txt: Added.
        * layout-tests/editing/deleting/smart-delete-001.html: Added.
        * layout-tests/editing/deleting/smart-delete-002-expected.txt: Added.
        * layout-tests/editing/deleting/smart-delete-002.html: Added.

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

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

diff --git a/LayoutTests/editing/deleting/smart-delete-001-expected.txt b/LayoutTests/editing/deleting/smart-delete-001-expected.txt
new file mode 100644 (file)
index 0000000..38d1a7f
--- /dev/null
@@ -0,0 +1,30 @@
+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 784x212 [border: (2px solid #0000FF)]
+        RenderBlock {DIV} at (14,14) size 756x56
+          RenderText {TEXT} at (0,0) size 67x28
+            text run at (0,0) width 67: "Tests: "
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (0,28) size 498x28
+            text run at (0,28) width 498: "Smart delete when deleting the first word on a line."
+        RenderBlock {DIV} at (14,86) size 756x112
+          RenderText {TEXT} at (0,0) size 189x28
+            text run at (0,0) width 189: "Expected Results: "
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (0,28) size 714x56
+            text run at (0,28) width 714: "The first word and the space following the first word should be deleted. It"
+            text run at (0,56) width 202: "should like this this: "
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (0,84) size 71x28
+            text run at (0,84) width 71: "bar baz"
+      RenderBlock {DIV} at (0,236) size 784x32
+        RenderBlock {DIV} at (0,0) size 784x32 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (2,2) size 71x28
+            text run at (2,2) width 71: "bar baz"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 1 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/deleting/smart-delete-001.html b/LayoutTests/editing/deleting/smart-delete-001.html
new file mode 100644 (file)
index 0000000..b48ec24
--- /dev/null
@@ -0,0 +1,60 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+.scenario { margin-bottom: 16px;}
+.scenario:first-line { font-weight: bold; margin-bottom: 16px;}
+.expected-results:first-line { font-weight: bold }
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByWordCommand();
+    deleteCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body>
+
+<div class="explanation">
+<div class="scenario">
+Tests: 
+<br>
+Smart delete when deleting the first word on a line.
+</div>
+<div class="expected-results">
+Expected Results:
+<br>
+The first word and the space following the first word should be deleted. It should like this this:
+<BR>
+bar baz
+</div>
+</div>
+
+<div contenteditable id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo bar baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/smart-delete-002-expected.txt b/LayoutTests/editing/deleting/smart-delete-002-expected.txt
new file mode 100644 (file)
index 0000000..619301c
--- /dev/null
@@ -0,0 +1,30 @@
+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 784x212 [border: (2px solid #0000FF)]
+        RenderBlock {DIV} at (14,14) size 756x56
+          RenderText {TEXT} at (0,0) size 67x28
+            text run at (0,0) width 67: "Tests: "
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (0,28) size 522x28
+            text run at (0,28) width 522: "Smart delete when deleting the second word of a line."
+        RenderBlock {DIV} at (14,86) size 756x112
+          RenderText {TEXT} at (0,0) size 189x28
+            text run at (0,0) width 189: "Expected Results: "
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (0,28) size 738x56
+            text run at (0,28) width 738: "The second word and the space before the second word should be deleted. It"
+            text run at (0,56) width 202: "should like this this: "
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (0,84) size 72x28
+            text run at (0,84) width 72: "foo baz"
+      RenderBlock {DIV} at (0,236) size 784x32
+        RenderBlock {DIV} at (0,0) size 784x32 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (2,2) size 72x28
+            text run at (2,2) width 72: "foo baz"
+selection is CARET:
+start:      position 4 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+upstream:   position 4 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+downstream: position 4 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/deleting/smart-delete-002.html b/LayoutTests/editing/deleting/smart-delete-002.html
new file mode 100644 (file)
index 0000000..54a550d
--- /dev/null
@@ -0,0 +1,62 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+.scenario { margin-bottom: 16px;}
+.scenario:first-line { font-weight: bold; margin-bottom: 16px;}
+.expected-results:first-line { font-weight: bold }
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByWordCommand();
+    moveSelectionForwardByCharacterCommand();
+    extendSelectionForwardByWordCommand();
+    deleteCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body>
+
+<div class="explanation">
+<div class="scenario">
+Tests: 
+<br>
+Smart delete when deleting the second word of a line.
+</div>
+<div class="expected-results">
+Expected Results:
+<br>
+The second word and the space before the second word should be deleted. It should like this this:
+<BR>
+foo baz
+</div>
+</div>
+
+<div contenteditable id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo bar baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 07ebde7374bad87634eabd5acd3ea003f7ae35e0..3e9441121f64852493274fc3adaa2fbd8be151f6 100644 (file)
@@ -1,3 +1,17 @@
+2005-03-01  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/4030669> smart delete does not delete spaces from pasted content
+
+        Reviewed by rjw.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::initializePositionData): pass true for treatNBSPAsWhiteSpace to leadingWhitespacePosition and trailingWhitespacePosition when testing whether or not we have to delete those characters as well.
+        * khtml/editing/jsediting.cpp: pass true for smartDelete when the selection granularity is WORD. This allows us to write smart delete layout tests.
+        * layout-tests/editing/deleting/smart-delete-001-expected.txt: Added.
+        * layout-tests/editing/deleting/smart-delete-001.html: Added.
+        * layout-tests/editing/deleting/smart-delete-002-expected.txt: Added.
+        * layout-tests/editing/deleting/smart-delete-002.html: Added.
+
 2005-03-01  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Vicki
index 726a241acefe987c786c59f6fbb1ad6226302a1f..e3f2a19dc3fff65286597c35bced949bd4d17589 100644 (file)
@@ -2343,27 +2343,31 @@ void DeleteSelectionCommand::initializePositionData()
     // Handle leading and trailing whitespace, as well as smart delete adjustments to the selection
     //
     m_leadingWhitespace = m_upstreamStart.leadingWhitespacePosition(m_selectionToDelete.startAffinity());
-    bool hasLeadingWhitespaceBeforeAdjustment = m_leadingWhitespace.isNotNull();
-    if (m_smartDelete && hasLeadingWhitespaceBeforeAdjustment) {
-        VisiblePosition visiblePos = VisiblePosition(start, m_selectionToDelete.startAffinity()).previous();
-        Position pos = visiblePos.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(visiblePos.affinity());
-    }
     m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition(VP_DEFAULT_AFFINITY);
-    // 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, m_selectionToDelete.endAffinity()).next().deepEquivalent();
-        m_upstreamEnd = pos.upstream(StayInBlock);
-        m_downstreamEnd = pos.downstream(StayInBlock);
-        m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition(VP_DEFAULT_AFFINITY);
+
+    if (m_smartDelete) {
+        bool hasLeadingWhitespaceBeforeAdjustment = m_upstreamStart.leadingWhitespacePosition(m_selectionToDelete.startAffinity(), true).isNotNull();
+        if (hasLeadingWhitespaceBeforeAdjustment) {
+            VisiblePosition visiblePos = VisiblePosition(start, m_selectionToDelete.startAffinity()).previous();
+            Position pos = visiblePos.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(visiblePos.affinity());
+        }
+        // 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 (!hasLeadingWhitespaceBeforeAdjustment && m_downstreamEnd.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNotNull()) {
+            // Expand out one character downstream for smart delete and recalculate
+            // positions based on this change.
+            Position pos = VisiblePosition(end, m_selectionToDelete.endAffinity()).next().deepEquivalent();
+            m_upstreamEnd = pos.upstream(StayInBlock);
+            m_downstreamEnd = pos.downstream(StayInBlock);
+            m_trailingWhitespace = m_downstreamEnd.trailingWhitespacePosition(VP_DEFAULT_AFFINITY);
+        }
     }
+    
     m_trailingWhitespaceValid = true;
     
     //
index f9c847f047553dcdeedf6f87316ffa4f89a102a4..c153c36f5a30fd572ec4fe9b42cc16997a25c96e 100644 (file)
@@ -210,7 +210,7 @@ bool execCut(KHTMLPart *part, bool userInterface, const DOMString &value)
 
 bool execDelete(KHTMLPart *part, bool userInterface, const DOMString &value)
 {
-    TypingCommand::deleteKeyPressed(part->xmlDocImpl());
+    TypingCommand::deleteKeyPressed(part->xmlDocImpl(), part->selectionGranularity() == khtml::WORD);
     return true;
 }