Title: [121357] trunk
Revision
121357
Author
[email protected]
Date
2012-06-27 12:42:22 -0700 (Wed, 27 Jun 2012)

Log Message

REGRESSION (Safari 5?): Pasting a line into textarea inserts two newlines
https://bugs.webkit.org/show_bug.cgi?id=49288

Reviewed by Tony Chang.

Source/WebCore: 

The bug was caused by positionAvoidingPrecedingNodes getting out of a block when the insertion point is at a line break.
It caused the subsequent code to be misinformed of the insertion position and ended up not pruning the extra line break.

Fixed the bug by checking this special case and bailing out so that we don't crawl out of the enclosing block.
It's similar to checks several lines below it.

Test: editing/pasteboard/copy-paste-pre-line-content.html

* editing/ReplaceSelectionCommand.cpp:
(WebCore::positionAvoidingPrecedingNodes):

LayoutTests: 

Add a test regerssion test for copying & pasting a line in pre into textarea twice.

* editing/pasteboard/copy-paste-pre-line-content-expected.txt: Added.
* editing/pasteboard/copy-paste-pre-line-content.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (121356 => 121357)


--- trunk/LayoutTests/ChangeLog	2012-06-27 18:45:01 UTC (rev 121356)
+++ trunk/LayoutTests/ChangeLog	2012-06-27 19:42:22 UTC (rev 121357)
@@ -1,3 +1,15 @@
+2012-06-27  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (Safari 5?): Pasting a line into textarea inserts two newlines
+        https://bugs.webkit.org/show_bug.cgi?id=49288
+
+        Reviewed by Tony Chang.
+
+        Add a test regerssion test for copying & pasting a line in pre into textarea twice.
+
+        * editing/pasteboard/copy-paste-pre-line-content-expected.txt: Added.
+        * editing/pasteboard/copy-paste-pre-line-content.html: Added.
+
 2012-06-27  Alpha Lam  <[email protected]>
 
         [Chromium] Rebaseline svg/text/scaled-font.svg and svg/text/scaling-font-with-geometric-precision.html caused by r121343.

Added: trunk/LayoutTests/editing/pasteboard/copy-paste-pre-line-content-expected.txt (0 => 121357)


--- trunk/LayoutTests/editing/pasteboard/copy-paste-pre-line-content-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-paste-pre-line-content-expected.txt	2012-06-27 19:42:22 UTC (rev 121357)
@@ -0,0 +1,8 @@
+This tests pasting two lines of text copied from pre content. To manually test, copy the selected text (including the new line) and paste it into textarea twice. There should be no blank line between two pasted lines.
+
+A line of text
+some other text
+
+A line of text
+A line of text
+

Added: trunk/LayoutTests/editing/pasteboard/copy-paste-pre-line-content.html (0 => 121357)


--- trunk/LayoutTests/editing/pasteboard/copy-paste-pre-line-content.html	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-paste-pre-line-content.html	2012-06-27 19:42:22 UTC (rev 121357)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This tests pasting two lines of text copied from pre content.
+To manually test, copy the selected text (including the new line) and paste it into textarea twice.
+There should be no blank line between two pasted lines.</p>
+<pre _oncopy_="setTimeout(function () { textarea.focus(); }, 0);">A line of text
+some other text
+</pre>
+
+<textarea cols="10" rows="5" _oninput_="document.getElementById('console').textContent = textarea.value;"></textarea>
+<pre id="console"></pre>
+<script>
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var textarea = document.querySelector('textarea');
+
+getSelection().collapse(document.querySelector('pre'), 0);
+getSelection().modify('extend', 'forward', 'line');
+
+if (document.queryCommandSupported('paste')) {
+    document.execCommand('copy', false, null);
+
+    textarea.focus();
+    document.execCommand('paste', false, null);
+    document.execCommand('paste', false, null);
+}
+
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (121356 => 121357)


--- trunk/Source/WebCore/ChangeLog	2012-06-27 18:45:01 UTC (rev 121356)
+++ trunk/Source/WebCore/ChangeLog	2012-06-27 19:42:22 UTC (rev 121357)
@@ -1,3 +1,21 @@
+2012-06-27  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (Safari 5?): Pasting a line into textarea inserts two newlines
+        https://bugs.webkit.org/show_bug.cgi?id=49288
+
+        Reviewed by Tony Chang.
+
+        The bug was caused by positionAvoidingPrecedingNodes getting out of a block when the insertion point is at a line break.
+        It caused the subsequent code to be misinformed of the insertion position and ended up not pruning the extra line break.
+
+        Fixed the bug by checking this special case and bailing out so that we don't crawl out of the enclosing block.
+        It's similar to checks several lines below it.
+
+        Test: editing/pasteboard/copy-paste-pre-line-content.html
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::positionAvoidingPrecedingNodes):
+
 2012-06-27  Andrei Onea  <[email protected]>
 
         [CSSRegions]Change display values that allow regions

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (121356 => 121357)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-06-27 18:45:01 UTC (rev 121356)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-06-27 19:42:22 UTC (rev 121357)
@@ -123,6 +123,9 @@
     // The two positions above are the same visual position, but we want to stay in the same block.
     Node* enclosingBlockNode = enclosingBlock(pos.containerNode());
     for (Position nextPosition = pos; nextPosition.containerNode() != enclosingBlockNode; pos = nextPosition) {
+        if (lineBreakExistsAtPosition(pos))
+            break;
+
         if (pos.containerNode()->nonShadowBoundaryParentNode())
             nextPosition = positionInParentAfterNode(pos.containerNode());
         
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to