Reviewed by John
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Sep 2004 16:54:12 +0000 (16:54 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Sep 2004 16:54:12 +0000 (16:54 +0000)
        Fix for this bug:

        <rdar://problem/3800346> Inserting newline in BR after block not working

        * khtml/editing/htmlediting_impl.cpp:
        (khtml::InputNewlineCommandImpl::doApply): The code to insert the "extra" BR at the end
        of blocks (hack done to make BRs show up when they appear at the ends of blocks) did not
        cover this one quirky case where the insertion point can be placed in a BR at the end of
        a block that does actually render. Now the input newline code can handle this addtional
        case.
        * layout-tests/editing/selection/insert-3800346-fix-expected.txt: Added.
        * layout-tests/editing/selection/insert-3800346-fix.html: Added.

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

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

diff --git a/LayoutTests/editing/inserting/insert-3800346-fix-expected.txt b/LayoutTests/editing/inserting/insert-3800346-fix-expected.txt
new file mode 100644 (file)
index 0000000..17d4996
--- /dev/null
@@ -0,0 +1,22 @@
+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 784x244 [border: (2px solid #FF0000)]
+        RenderBlock {DIV} at (14,14) size 756x216
+          RenderBlock (anonymous) at (0,0) size 756x28
+            RenderText {TEXT} at (0,0) size 42x28
+              text run at (0,0) width 42: "Test"
+          RenderBlock {BLOCKQUOTE} at (40,52) size 676x28
+            RenderText {TEXT} at (0,0) size 42x28
+              text run at (0,0) width 42: "Test"
+          RenderBlock (anonymous) at (0,104) size 756x112
+            RenderBR {BR} at (0,0) size 0x28
+            RenderBR {BR} at (0,28) size 0x28
+            RenderBR {BR} at (0,56) size 0x28
+            RenderBR {BR} at (0,84) size 0x28
+selection is CARET:
+start:      position 0 of child 6 {BR} of child 2 {DIV} of root {DIV}
+upstream:   position 1 of child 5 {BR} of child 2 {DIV} of root {DIV}
+downstream: position 0 of child 6 {BR} of child 2 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/inserting/insert-3800346-fix.html b/LayoutTests/editing/inserting/insert-3800346-fix.html
new file mode 100644 (file)
index 0000000..782e8ca
--- /dev/null
@@ -0,0 +1,36 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    for (i = 0; i < 15; i++)
+        moveSelectionForwardByCharacterCommand();
+    for (i = 0; i < 3; i++)
+        insertNewlineCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body>
+<div contenteditable id="root" class="editing">
+<div id="test">Test<BLOCKQUOTE>Test</BLOCKQUOTE><BR></div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index a008a07..bc84303 100644 (file)
@@ -1,3 +1,20 @@
+2004-09-14  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by John
+
+        Fix for this bug:
+        
+        <rdar://problem/3800346> Inserting newline in BR after block not working
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::InputNewlineCommandImpl::doApply): The code to insert the "extra" BR at the end
+        of blocks (hack done to make BRs show up when they appear at the ends of blocks) did not
+        cover this one quirky case where the insertion point can be placed in a BR at the end of 
+        a block that does actually render. Now the input newline code can handle this addtional
+        case.
+        * layout-tests/editing/selection/insert-3800346-fix-expected.txt: Added.
+        * layout-tests/editing/selection/insert-3800346-fix.html: Added.
+
 2004-09-14  Darin Adler  <darin@apple.com>
 
         Reviewed by Ken.
index b574a30..271c1bb 100644 (file)
@@ -1391,18 +1391,24 @@ void InputNewlineCommandImpl::doApply()
         // This makes the "real" BR we want to insert appear in the rendering without any 
         // significant side effects (and no real worries either since you can't arrow past 
         // this extra one.
-        NodeImpl *next = pos.node()->traverseNextNode();
-        bool hasTrailingBR = next && next->id() == ID_BR;
-        insertNodeAfterPosition(nodeToInsert, pos);
-        if (hasTrailingBR) {
-            setEndingSelection(Position(next, 0));
+        if (pos.node()->id() == ID_BR && pos.offset() == 0) {
+            // Already placed in a trailing BR. Insert "real" BR before it and leave the selection alone.
+            insertNodeBefore(nodeToInsert, pos.node());
         }
         else {
-            // Insert an "extra" BR at the end of the block. 
-            ElementImpl *extraBreakNode = document()->createHTMLElement("BR", exceptionCode);
-            ASSERT(exceptionCode == 0);
-            insertNodeAfter(extraBreakNode, nodeToInsert);
-            setEndingSelection(Position(extraBreakNode, 0));
+            NodeImpl *next = pos.node()->traverseNextNode();
+            bool hasTrailingBR = next && next->id() == ID_BR && pos.node()->enclosingBlockFlowElement() == next->enclosingBlockFlowElement();
+            insertNodeAfterPosition(nodeToInsert, pos);
+            if (hasTrailingBR) {
+                setEndingSelection(Position(next, 0));
+            }
+            else {
+                // Insert an "extra" BR at the end of the block. 
+                ElementImpl *extraBreakNode = document()->createHTMLElement("BR", exceptionCode);
+                ASSERT(exceptionCode == 0);
+                insertNodeAfter(extraBreakNode, nodeToInsert);
+                setEndingSelection(Position(extraBreakNode, 0));
+            }
         }
     }
     else if (atStart) {