Bug 49288 - REGRESSION (Safari 5?): Pasting a line into textarea inserts two newlines
Summary: REGRESSION (Safari 5?): Pasting a line into textarea inserts two newlines
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh OS X 10.6
: P2 Normal
Assignee: Ryosuke Niwa
Keywords: InRadar
Depends on:
Reported: 2010-11-09 17:11 PST by Alexey Proskuryakov
Modified: 2012-06-27 12:42 PDT (History)
9 users (show)

See Also:

Fixes the bug (4.61 KB, patch)
2012-06-27 02:28 PDT, Ryosuke Niwa
tony: review+
tony: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Proskuryakov 2010-11-09 17:11:07 PST
Steps to reproduce:
1. Select and copy this whole line in Bugzilla (e.g. via triple-click and Cmd+C).
2. Paste it into additional comments field several times.

There are empty lines between pasted lines, suggesting that two newlines are getting pasted instead of one.

This is rather annoying, I hit this multiple times a day in Bugzilla. This only started to happen time ago - assuming that was Safari 5, but I'm not sure.
Comment 1 Marijn Haverbeke 2012-06-25 11:45:40 PDT
CodeMirror (http://codemirror.net) uses a textarea in a way that makes this bug extra visible. I've had several people report it as a bug in CodeMirror in the past few months [1][2][3], and in fact ran into it writing this very comment in the bug tracker.

This seems a serious, obviously reproduceable bug. I hope it's still on someone's list? (Has been sitting idle in the bug tracker for a long time now.)

[1]: https://github.com/marijnh/CodeMirror2/issues/598
[2]: https://github.com/marijnh/CodeMirror2/issues/474
[3]: http://groups.google.com/group/codemirror/browse_thread/thread/9b42dec8a17a2dc1
Comment 2 Simon Fraser (smfr) 2012-06-25 20:46:37 PDT
This is also important for Adobe's Brackets editor.
Comment 3 Radar WebKit Bug Importer 2012-06-25 20:47:07 PDT
Comment 4 Ryosuke Niwa 2012-06-26 00:22:19 PDT

Index: Source/WebCore/editing/ReplaceSelectionCommand.cpp
--- Source/WebCore/editing/ReplaceSelectionCommand.cpp	(revision 121106)
+++ Source/WebCore/editing/ReplaceSelectionCommand.cpp	(working copy)
@@ -123,9 +123,12 @@
     // 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());
         if (nextPosition == pos 
             || enclosingBlock(nextPosition.containerNode()) != enclosingBlockNode
             || VisiblePosition(pos) != VisiblePosition(nextPosition))

I'll post a patch tomorrow.
Comment 5 Ryosuke Niwa 2012-06-26 00:49:11 PDT
Maybe caused by http://trac.webkit.org/changeset/55762 ?
Comment 6 Tony Chang 2012-06-26 12:46:48 PDT
(In reply to comment #5)
> Maybe caused by http://trac.webkit.org/changeset/55762 ?

Seems possible. I probably didn't consider the impact on plain text by moving to an equivalent visual position.
Comment 7 Ryosuke Niwa 2012-06-27 02:28:05 PDT
Created attachment 149714 [details]
Fixes the bug
Comment 8 Marijn Haverbeke 2012-06-27 02:33:17 PDT
Thank you for figuring this out!
Comment 9 Tony Chang 2012-06-27 10:35:01 PDT
Comment on attachment 149714 [details]
Fixes the bug

View in context: https://bugs.webkit.org/attachment.cgi?id=149714&action=review

> LayoutTests/ChangeLog:8
> +        Add a test regerssion test for copying & pasting a line in pre into textarea twice.

Typo regression and I think you don't mean to say test twice.
Comment 10 Ryosuke Niwa 2012-06-27 12:42:27 PDT
Committed r121357: <http://trac.webkit.org/changeset/121357>