LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Apr 2006 18:14:47 +0000 (18:14 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Apr 2006 18:14:47 +0000 (18:14 +0000)
        Reviewed by harrison

        * editing/pasteboard/merge-end-3-expected.checksum: Added.
        * editing/pasteboard/merge-end-3-expected.png: Added.
        * editing/pasteboard/merge-end-3-expected.txt: Added.
        * editing/pasteboard/merge-end-3.html: Added.

WebCore:

        Reviewed by harrison

        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::moveParagraph): The placeholder that's inserted
        to keep content from collapsing due to pruning was inserted at the position after
        the moved paragraph.  That's only appropriate when moving the paragraph backward
        into the previous paragraph.

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply): The last paragraph of the incoming
        fragment should be merged with the paragraph after the end of the selection being pasted
        into even if the incoming fragment has only one block.   This fixes a bug and gets
        rid of a use of the info gathered during the test insertion.

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/merge-end-3-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-3-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-3-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/merge-end-3.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/CompositeEditCommand.cpp
WebCore/editing/ReplaceSelectionCommand.cpp

index 0f591cd..66be8b6 100644 (file)
@@ -1,3 +1,12 @@
+2006-04-18  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+
+        * editing/pasteboard/merge-end-3-expected.checksum: Added.
+        * editing/pasteboard/merge-end-3-expected.png: Added.
+        * editing/pasteboard/merge-end-3-expected.txt: Added.
+        * editing/pasteboard/merge-end-3.html: Added.
+
 2006-04-17  Adele Peterson  <adele@apple.com>
 
         Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=8407
diff --git a/LayoutTests/editing/pasteboard/merge-end-3-expected.checksum b/LayoutTests/editing/pasteboard/merge-end-3-expected.checksum
new file mode 100644 (file)
index 0000000..a7c412e
--- /dev/null
@@ -0,0 +1 @@
+772a8f6f5f07ffb3dc875020b762872e
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/merge-end-3-expected.png b/LayoutTests/editing/pasteboard/merge-end-3-expected.png
new file mode 100644 (file)
index 0000000..0bec7ec
Binary files /dev/null and b/LayoutTests/editing/pasteboard/merge-end-3-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/merge-end-3-expected.txt b/LayoutTests/editing/pasteboard/merge-end-3-expected.txt
new file mode 100644 (file)
index 0000000..65eb494
--- /dev/null
@@ -0,0 +1,26 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 3 of #text > DIV > DIV > BODY > HTML > #document to 3 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+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 {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 549x18
+          text run at (0,0) width 549: "The last paragraph of the incoming fragment should be in the same paragraph as 'three'."
+      RenderBlock {DIV} at (0,34) size 784x36
+        RenderBlock (anonymous) at (0,0) size 784x18
+          RenderText {#text} at (0,0) size 27x18
+            text run at (0,0) width 27: "one "
+        RenderBlock {DIV} at (0,18) size 784x18
+          RenderText {#text} at (0,0) size 24x18
+            text run at (0,0) width 24: "two"
+          RenderText {#text} at (24,0) size 31x18
+            text run at (24,0) width 31: "three"
+caret: position 3 of child 0 {#text} of child 1 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/merge-end-3.html b/LayoutTests/editing/pasteboard/merge-end-3.html
new file mode 100644 (file)
index 0000000..79f78b0
--- /dev/null
@@ -0,0 +1,14 @@
+<p>The last paragraph of the incoming fragment should be in the same paragraph as 'three'.</p> 
+<div id="test" contenteditable="true">one three</div>
+
+<script>
+var s = window.getSelection();
+var e = document.getElementById("test");
+
+s.setPosition(e, 0);
+s.modify("move", "forward", "word");
+s.modify("move", "forward", "character");
+
+document.execCommand("InsertHTML", false , "<br class='Apple-interchange-newline'><div>two</div>");
+
+</script>
\ No newline at end of file
index fb18f04..67feb5c 100644 (file)
@@ -1,3 +1,19 @@
+2006-04-17  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::moveParagraph): The placeholder that's inserted 
+        to keep content from collapsing due to pruning was inserted at the position after 
+        the moved paragraph.  That's only appropriate when moving the paragraph backward 
+        into the previous paragraph.
+        
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply): The last paragraph of the incoming
+        fragment should be merged with the paragraph after the end of the selection being pasted
+        into even if the incoming fragment has only one block.   This fixes a bug and gets
+        rid of a use of the info gathered during the test insertion.
+
 2006-04-17  Adele Peterson  <adele@apple.com>
 
         Reviewed by Darin.
index b0517e8..33bd993 100644 (file)
@@ -673,6 +673,8 @@ void CompositeEditCommand::moveParagraph(const VisiblePosition& startOfParagraph
     ASSERT(isStartOfParagraph(startOfParagraphToMove));
     ASSERT(isEndOfParagraph(endOfParagraphToMove));
     
+    VisiblePosition beforeParagraph = startOfParagraphToMove.previous();
+    
     Position start = startOfParagraphToMove.deepEquivalent().upstream();
     // We upstream() the end so that we don't include collapsed whitespace in the move.
     // If we must later add a br after the moved paragraph, doing so would cause the moved unrendered space to become rendered.
@@ -703,8 +705,8 @@ void CompositeEditCommand::moveParagraph(const VisiblePosition& startOfParagraph
     // baz
     // Imagine moving 'bar' to ^.  'bar' will be deleted and its div pruned.  That would
     // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br.
-    if (!isEndOfParagraph(destination))
-        insertNodeAt(createBreakElement(document()).get(), destination.deepEquivalent().node(), destination.deepEquivalent().offset());
+    if (beforeParagraph.isNotNull() && !isEndOfParagraph(beforeParagraph))
+        insertNodeAt(createBreakElement(document()).get(), beforeParagraph.deepEquivalent().node(), beforeParagraph.deepEquivalent().offset());
     
     setEndingSelection(destination);
     EditCommandPtr cmd(new ReplaceSelectionCommand(document(), fragment.get(), false));
index 4956856..4873666 100644 (file)
@@ -488,7 +488,6 @@ void ReplaceSelectionCommand::doApply()
     bool startAtStartOfBlock = isStartOfBlock(visibleStart);
     bool startAtEndOfBlock = isEndOfBlock(visibleStart);
     Node *startBlock = selection.start().node()->enclosingBlockFlowElement();
-    Node *endBlock = selection.end().node()->enclosingBlockFlowElement();
 
     // decide whether to later merge content into the startBlock
     bool mergeStart = false;
@@ -523,11 +522,8 @@ void ReplaceSelectionCommand::doApply()
         }
     }
     
-    // decide whether to later append nodes to the end
-    Node *beyondEndNode = 0;
-    if (!isEndOfParagraph(visibleEnd) && !fragment.hasInterchangeNewlineAtEnd() &&
-       (startBlock != endBlock || fragment.hasMoreThanOneBlock()))
-        beyondEndNode = selection.end().downstream().node();
+    // Whether the last paragraph of the incoming fragment should be merged with content from visibleEnd to endOfParagraph(visibleEnd).
+    bool mergeEnd = !isEndOfParagraph(visibleEnd) && !fragment.hasInterchangeNewlineAtEnd();
 
     Position startPos = selection.start();
     
@@ -791,11 +787,15 @@ void ReplaceSelectionCommand::doApply()
             }
         }
         
-        if (beyondEndNode) {
-            VisiblePosition startOfParagraphToMove(Position(beyondEndNode, 0));
-            VisiblePosition endOfParagraphToMove = endOfParagraph(startOfParagraphToMove);
-            VisiblePosition destination(Position(m_lastNodeInserted->parentNode(), m_lastNodeInserted->nodeIndex() + 1));
-            moveParagraph(startOfParagraphToMove, endOfParagraphToMove, destination);
+        if (mergeEnd) {
+            // FIXME: This move should happen in the opposite direction, because we'd rather preserve the styles on the block containing the 
+            // paragraph that was already in the document than preserve block styles from the incoming fragment. 
+            VisiblePosition afterInsertedContent(Position(m_lastNodeInserted->parentNode(), m_lastNodeInserted->nodeIndex() + 1));
+            if (isEndOfParagraph(afterInsertedContent)) {
+                VisiblePosition startOfParagraphToMove = afterInsertedContent.next();
+                VisiblePosition endOfParagraphToMove = endOfParagraph(startOfParagraphToMove);
+                moveParagraph(startOfParagraphToMove, endOfParagraphToMove, afterInsertedContent);
+            }
         }
     }