Bug 24009 - WebKit nests block elements when pasting paragraphs
Summary: WebKit nests block elements when pasting paragraphs
Status: RESOLVED DUPLICATE of bug 26483
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL: http://www.mozilla.org/editor/midasdemo/
Keywords:
: 32232 39193 (view as bug list)
Depends on: 34564 44220
Blocks:
  Show dependency treegraph
 
Reported: 2009-02-18 13:59 PST by Eric Seidel (no email)
Modified: 2011-08-16 19:56 PDT (History)
8 users (show)

See Also:


Attachments
work in progress (works for very simple case with p tag) (3.99 KB, patch)
2010-08-17 20:53 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
work in progress 2 (9.14 KB, patch)
2010-08-18 15:03 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
needs more test conversion but ready for early review (19.31 KB, patch)
2010-08-21 20:45 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2009-02-18 13:59:04 PST
Safari can create invalid HTML when pasting paragraphs

I'm not sure I know what the "right" behavior is here, but our current behavior seems "wrong".

editable content:
<p>test</p>

Select All (command-a)
Copy
Paste

resulting editable content (in WebKit):
<p><p>test</p></p>

FF:
<p>test</p>

I've not tested IE yet.

I was using:
http://www.mozilla.org/editor/midasdemo/
for my testing.
Comment 1 Tony Chang 2010-02-01 22:39:39 PST
The original test case doesn't repro for me, but if I change the editable content to <p>first</p><p><br></p>, I'm able to repro.

Also, this isn't specific to <p> tags, any block tag will cause this.  E.g.,
<blockquote>first</blockquote><blockquote><br/></blockquote> + select all + copy + paste will result in nested blockquotes:
<blockquote><blockquote>first</blockquote><div><br></div></blockquote>

For div's this isn't as apparent because the nesting is harmless.
Comment 2 Tony Chang 2010-05-27 23:52:02 PDT
*** Bug 39193 has been marked as a duplicate of this bug. ***
Comment 3 Ryosuke Niwa 2010-08-17 20:03:18 PDT
*** Bug 32232 has been marked as a duplicate of this bug. ***
Comment 4 Ryosuke Niwa 2010-08-17 20:53:52 PDT
Created attachment 64667 [details]
work in progress (works for very simple case with p tag)
Comment 5 Tony Chang 2010-08-18 09:30:23 PDT
(In reply to comment #4)
> Created an attachment (id=64667) [details]
> work in progress (works for very simple case with p tag)

This sounds similar to https://bugs.webkit.org/show_bug.cgi?id=39866, which is a generalization of https://bugs.webkit.org/show_bug.cgi?id=25002.  See Ojan's comment on 39866.
Comment 6 Ryosuke Niwa 2010-08-18 15:03:48 PDT
Created attachment 64780 [details]
work in progress 2
Comment 7 Ryosuke Niwa 2010-08-18 15:11:09 PDT
areIdenticalElements is copied from ApplyStyleCommand, I'll be sharing it between ApplyStyleCommand and ReplaceSelectionCommand in my final patch.

This patch currently requires 3 rebaselines: editing/pasteboard/4242293-1.html, editing/pasteboard/copy-paste-bidi.html, and editing/selection/replace-selection-crash.html.  The first two tests need to be converted to dumpAsMarkup or dumpAsText tests first.  But changes are good as far as I looked at the render tree.

This patch does not fix the bug 26483 because of the bug 34564.  We could work-around the issue by handling style spans before pasting.  But the correct thing to do is not to wrap everything with style-spans.  It shouldn't be too hard to push styles to each element in the fragment and have ReplaceSelectionCommand remove all redundant styles at the pasting stage.  But we should probably do that in a separate patch.
Comment 8 Ryosuke Niwa 2010-08-21 20:45:37 PDT
Created attachment 65045 [details]
needs more test conversion but ready for early review
Comment 9 Ryosuke Niwa 2010-08-21 20:53:12 PDT
My new approach changes the behavior of WebKit so that it doesn't merge the inserted paragraph and the paragraph in the destination when the inserted content starts with the same block element as the destination.  For this change,
editing/pasteboard/8145-3.html
editing/pasteboard/interchange-newline-2.html
editing/pasteboard/merge-after-delete.html
editing/pasteboard/merge-end-list.html
need to be rebaselined.  All four tests should be converted to dump-as-markup tests first.
Comment 10 Ryosuke Niwa 2011-08-16 19:56:34 PDT

*** This bug has been marked as a duplicate of bug 26483 ***