Reviewed by Hyatt
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Aug 2004 21:34:20 +0000 (21:34 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Aug 2004 21:34:20 +0000 (21:34 +0000)
        Fix for this bug:

        <rdar://problem/3775316> document sprouts an extra newline character at the end

        * khtml/editing/htmlediting_impl.cpp:
        (khtml::InputNewlineCommandImpl::doApply): There was in insufficient check
        in the code which adds extra BR elements at the ends of blocks, which we do
        to work around the fact that BR elements, when they are the last element in a
        block, do not render. Now the code sees whether there already is one of these
        extra BR's in the document and won't add and "extra" extra.
        * layout-tests/editing/inserting/insert-3775316-fix.html: Added.

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

LayoutTests/editing/inserting/insert-3775316-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-3775316-fix.html b/LayoutTests/editing/inserting/insert-3775316-fix.html
new file mode 100644 (file)
index 0000000..91135f8
--- /dev/null
@@ -0,0 +1,40 @@
+<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() {
+    moveSelectionForwardByCharacterCommand();
+    insertNewlineCommand();
+    typeCharacterCommand();
+    selectAllCommand();
+    deleteCommand();
+    typeCharacterCommand();
+    insertNewlineCommand();
+    typeCharacterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body>
+<div contenteditable id="root" class="editing">
+<span id="test">x</span>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 332047e9e64532b1c98ac86f5394ba0108034fc6..c7b28f01f4241b3279ee05ea34f448cd31565a04 100644 (file)
@@ -1,3 +1,19 @@
+2004-08-26  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Hyatt
+
+        Fix for this bug:
+        
+        <rdar://problem/3775316> document sprouts an extra newline character at the end
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::InputNewlineCommandImpl::doApply): There was in insufficient check
+        in the code which adds extra BR elements at the ends of blocks, which we do 
+        to work around the fact that BR elements, when they are the last element in a
+        block, do not render. Now the code sees whether there already is one of these
+        extra BR's in the document and won't add and "extra" extra. 
+        * layout-tests/editing/inserting/insert-3775316-fix.html: Added.
+
 2004-08-26  David Hyatt  <hyatt@apple.com>
 
        Fix for 3710721 and 3504114, crashes because of bad ownership model for list markers.
index f7e5004c3d2eae1d59a326dc00c6bd51b5a6255a..b2724a81346bd39b3323cda43cc4bd547e82c859 100644 (file)
@@ -1346,15 +1346,23 @@ void InputNewlineCommandImpl::doApply()
     
     if (atEndOfBlock) {
         LOG(Editing, "input newline case 1");
-        // Insert an "extra" BR at the end of the block. 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.
+        // Check for a trailing BR. If there isn't one, we'll need to insert an "extra" one.
+        // 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);
-        exceptionCode = 0;
-        ElementImpl *extraBreakNode = document()->createHTMLElement("BR", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        insertNodeAfter(extraBreakNode, nodeToInsert);
-        setEndingSelection(Position(extraBreakNode, 0));
+        if (hasTrailingBR) {
+            setEndingSelection(Position(nodeToInsert, 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) {
         LOG(Editing, "input newline case 2");