<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[20660] trunk</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/20660">20660</a></dd>
<dt>Author</dt> <dd>justing</dd>
<dt>Date</dt> <dd>2007-04-02 11:23:42 -0700 (Mon, 02 Apr 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>LayoutTests:

        Reviewed by darin
        
        &lt;rdar://problem/5058163&gt; 
        Hitting return inserts a new line between two To Dos, but caret is position after second ToDo

        * editing/inserting/5058163-1-expected.checksum: Added.
        * editing/inserting/5058163-1-expected.png: Added.
        * editing/inserting/5058163-1-expected.txt: Added.
        * editing/inserting/5058163-1.html: Added.
        * editing/inserting/5058163-2-expected.checksum: Added.
        * editing/inserting/5058163-2-expected.png: Added.
        * editing/inserting/5058163-2-expected.txt: Added.
        * editing/inserting/5058163-2.html: Added.

WebCore:

        Reviewed by darin

        &lt;rdar://problem/5058163&gt; 
        Hitting return inserts a new line between two To Dos, but caret is position after second ToDo

        * editing/InsertParagraphSeparatorCommand.cpp:
        (WebCore::InsertParagraphSeparatorCommand::doApply):
        Removed refPos, it was unused.
        Don't assume that upstream() moves to a different
        node.  This assumption caused the line break to
        be inserted *after* the caret and a bad position
        to be set (added a testcase).
        Use isStartOfParagraph instead of checking
        for the existence of a br because the line might 
        be broken by a newline character in text that 
        preserves newlines.  Paragraphs that are created 
        in other ways, like with blocks, are handled 
        above (added a testcase).</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreeditingInsertParagraphSeparatorCommandcpp">trunk/WebCore/editing/InsertParagraphSeparatorCommand.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditinginserting50581631expectedchecksum">trunk/LayoutTests/editing/inserting/5058163-1-expected.checksum</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581631expectedpng">trunk/LayoutTests/editing/inserting/5058163-1-expected.png</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581631expectedtxt">trunk/LayoutTests/editing/inserting/5058163-1-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581631html">trunk/LayoutTests/editing/inserting/5058163-1.html</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581632expectedchecksum">trunk/LayoutTests/editing/inserting/5058163-2-expected.checksum</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581632expectedpng">trunk/LayoutTests/editing/inserting/5058163-2-expected.png</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581632expectedtxt">trunk/LayoutTests/editing/inserting/5058163-2-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditinginserting50581632html">trunk/LayoutTests/editing/inserting/5058163-2.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (20659 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2007-04-02 18:22:54 UTC (rev 20659)
+++ trunk/LayoutTests/ChangeLog        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2007-04-02  Justin Garcia  &lt;justin.garcia@apple.com&gt;
+
+        Reviewed by darin
+        
+        &lt;rdar://problem/5058163&gt; 
+        Hitting return inserts a new line between two To Dos, but caret is position after second ToDo
+
+        * editing/inserting/5058163-1-expected.checksum: Added.
+        * editing/inserting/5058163-1-expected.png: Added.
+        * editing/inserting/5058163-1-expected.txt: Added.
+        * editing/inserting/5058163-1.html: Added.
+        * editing/inserting/5058163-2-expected.checksum: Added.
+        * editing/inserting/5058163-2-expected.png: Added.
+        * editing/inserting/5058163-2-expected.txt: Added.
+        * editing/inserting/5058163-2.html: Added.
+
</ins><span class="cx"> 2007-03-31  Mitz Pettel  &lt;mitz@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Darin.
</span></span></pre></div>
<a id="trunkLayoutTestseditinginserting50581631expectedchecksum"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-1-expected.checksum (0 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/inserting/5058163-1-expected.checksum                                (rev 0)
+++ trunk/LayoutTests/editing/inserting/5058163-1-expected.checksum        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+9de55167e3572dc4199676d16f4c27a4
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestseditinginserting50581631expectedpng"></a>
<div class="binary"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-1-expected.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/LayoutTests/editing/inserting/5058163-1-expected.png
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:mime-type
</span><span class="cx">   + application/octet-stream
</span><a id="trunkLayoutTestseditinginserting50581631expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-1-expected.txt (0 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/inserting/5058163-1-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/inserting/5058163-1-expected.txt        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -0,0 +1,27 @@
</span><ins>+layer at (0,0) size 800x600
+  RenderView 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 759x18
+          text run at (0,0) width 759: &quot;This tests for a bug where hitting return between two tables would add a new paragraph at the end of the editable region.&quot;
+      RenderBlock {DIV} at (0,34) size 784x88
+        RenderTable {TABLE} at (0,0) size 475x26 [border: (1px solid #AAAAAA)]
+          RenderTableSection {TBODY} at (1,1) size 473x24
+            RenderTableRow {TR} at (0,2) size 473x20
+              RenderTableCell {TD} at (2,2) size 469x20 [r=0 c=0 rs=1 cs=1]
+                RenderText {#text} at (1,1) size 467x18
+                  text run at (1,1) width 467: &quot;There should be two empty paragraphs after this table and before the next.&quot;
+        RenderBlock (anonymous) at (0,26) size 784x18
+          RenderBR {BR} at (0,0) size 0x18
+        RenderBlock {DIV} at (0,44) size 784x44
+          RenderBlock (anonymous) at (0,0) size 784x18
+            RenderBR {BR} at (0,0) size 0x18
+          RenderTable {TABLE} at (0,18) size 276x26 [border: (1px solid #AAAAAA)]
+            RenderTableSection {TBODY} at (1,1) size 274x24
+              RenderTableRow {TR} at (0,2) size 274x20
+                RenderTableCell {TD} at (2,2) size 270x20 [r=0 c=0 rs=1 cs=1]
+                  RenderText {#text} at (1,1) size 268x18
+                    text run at (1,1) width 268: &quot;And the caret should be in the second one.&quot;
+caret: position 0 of child 0 {BR} of child 2 {DIV} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document
</ins></span></pre></div>
<a id="trunkLayoutTestseditinginserting50581631html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-1.html (0 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/inserting/5058163-1.html                                (rev 0)
+++ trunk/LayoutTests/editing/inserting/5058163-1.html        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+&lt;style&gt;
+table {
+    border: 1px solid #aaa;
+}
+&lt;/style&gt;
+&lt;p&gt;This tests for a bug where hitting return between two tables would add a new paragraph at the end of the editable region.&lt;/p&gt;
+&lt;div id=&quot;div&quot; contenteditable=&quot;true&quot;&gt;&lt;table contenteditable=&quot;false&quot;&gt;&lt;tr&gt;&lt;td contenteditable=&quot;true&quot;&gt;There should be two empty paragraphs after this table and before the next.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;table contenteditable=&quot;false&quot;&gt;&lt;tr&gt;&lt;td contenteditable=&quot;true&quot;&gt;And the caret should be in the second one.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
+&lt;script&gt;
+var sel = window.getSelection();
+var div = document.getElementById(&quot;div&quot;);
+sel.setPosition(div, 1);
+document.execCommand(&quot;InsertParagraph&quot;);
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestseditinginserting50581632expectedchecksum"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-2-expected.checksum (0 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/inserting/5058163-2-expected.checksum                                (rev 0)
+++ trunk/LayoutTests/editing/inserting/5058163-2-expected.checksum        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+e4c1832227aa8cc52e309ff3b8ee793e
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestseditinginserting50581632expectedpng"></a>
<div class="binary"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-2-expected.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/LayoutTests/editing/inserting/5058163-2-expected.png
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:mime-type
</span><span class="cx">   + application/octet-stream
</span><a id="trunkLayoutTestseditinginserting50581632expectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-2-expected.txt (0 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/inserting/5058163-2-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/inserting/5058163-2-expected.txt        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+layer at (0,0) size 800x600
+  RenderView 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 692x18
+          text run at (0,0) width 692: &quot;This tests for a bug where hitting return after a line break in text that preserves newlines wouldn't do anything.&quot;
+      RenderBlock {DIV} at (0,34) size 784x54
+        RenderBlock (anonymous) at (0,0) size 784x36
+          RenderText {#text} at (0,0) size 24x18
+            text run at (0,0) width 24: &quot;xxx&quot;
+            text run at (24,0) width 0: &quot; &quot;
+          RenderBR {BR} at (0,18) size 0x18
+        RenderBlock {DIV} at (0,36) size 784x18
+          RenderText {#text} at (0,0) size 663x18
+            text run at (0,0) width 663: &quot;There should be an empty paragraph before this one, and the caret should be at the start of this paragraph.&quot;
+caret: position 0 of child 0 {#text} of child 2 {DIV} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
</ins></span></pre></div>
<a id="trunkLayoutTestseditinginserting50581632html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/inserting/5058163-2.html (0 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/inserting/5058163-2.html                                (rev 0)
+++ trunk/LayoutTests/editing/inserting/5058163-2.html        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+&lt;p&gt;This tests for a bug where hitting return after a line break in text that preserves newlines wouldn't do anything.&lt;/p&gt;
+&lt;div id=&quot;div&quot; contenteditable=&quot;true&quot; style=&quot;white-space: pre;&quot;&gt;xxx
+There should be an empty paragraph before this one, and the caret should be at the start of this paragraph.&lt;/div&gt;
+&lt;script&gt;
+var sel = window.getSelection();
+var div = document.getElementById(&quot;div&quot;);
+var text = div.firstChild;
+sel.setPosition(text, 4);
+document.execCommand(&quot;InsertParagraph&quot;);
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (20659 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2007-04-02 18:22:54 UTC (rev 20659)
+++ trunk/WebCore/ChangeLog        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2007-04-02  Justin Garcia  &lt;justin.garcia@apple.com&gt;
+
+        Reviewed by darin
+
+        &lt;rdar://problem/5058163&gt; 
+        Hitting return inserts a new line between two To Dos, but caret is position after second ToDo
+
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::doApply):
+        Removed refPos, it was unused.
+        Don't assume that upstream() moves to a different
+        node.  This assumption caused the line break to
+        be inserted *after* the caret and a bad position
+        to be set (added a testcase).
+        Use isStartOfParagraph instead of checking
+        for the existence of a br because the line might 
+        be broken by a newline character in text that 
+        preserves newlines.  Paragraphs that are created 
+        in other ways, like with blocks, are handled 
+        above (added a testcase).
+
</ins><span class="cx">  2007-04-02  David Harrison  &lt;harrison@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Darin.
</span></span></pre></div>
<a id="trunkWebCoreeditingInsertParagraphSeparatorCommandcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/editing/InsertParagraphSeparatorCommand.cpp (20659 => 20660)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/editing/InsertParagraphSeparatorCommand.cpp        2007-04-02 18:22:54 UTC (rev 20659)
+++ trunk/WebCore/editing/InsertParagraphSeparatorCommand.cpp        2007-04-02 18:23:42 UTC (rev 20660)
</span><span class="lines">@@ -166,7 +166,6 @@
</span><span class="cx">     // similar case where previous position is in another, presumeably nested, block.
</span><span class="cx">     if (isFirstInBlock || !inSameBlock(visiblePos, visiblePos.previous())) {
</span><span class="cx">         pos = pos.downstream();
</span><del>-        Position refPos;
</del><span class="cx">         Node *refNode;
</span><span class="cx">         if (isFirstInBlock &amp;&amp; !nestNewBlock)
</span><span class="cx">             refNode = startBlock;
</span><span class="lines">@@ -187,10 +186,13 @@
</span><span class="cx">     //---------------------------------------------------------------------
</span><span class="cx">     // Handle the (more complicated) general case,
</span><span class="cx"> 
</span><del>-    Position upstreamPos = pos.upstream();
-    if (upstreamPos.node()-&gt;hasTagName(brTag)) {
</del><ins>+    // All of the content in the current block after visiblePos is
+    // about to be wrapped in a new paragraph element.  Add a br before 
+    // it if visiblePos is at the start of a paragraph so that the 
+    // content will move down a line.
+    if (isStartOfParagraph(visiblePos)) {
</ins><span class="cx">         RefPtr&lt;Element&gt; br = createBreakElement(document());
</span><del>-        insertNodeAfter(br.get(), upstreamPos.node());
</del><ins>+        insertNodeAt(br.get(), pos.node(), pos.offset());
</ins><span class="cx">         pos = positionAfterNode(br.get());
</span><span class="cx">     }
</span><span class="cx">     
</span></span></pre>
</div>
</div>

</body>
</html>