Bug 87330

Summary: Copy / paste inside PRE element re-inserts PRE element
Product: WebKit Reporter: jaroslav.benc
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ahmad.saleem792, ap, enrica, megan_gardner, rniwa, tony, wenson_hsieh
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Windows 7   
Attachments:
Description Flags
test case
none
work in progress none

Description jaroslav.benc 2012-05-23 18:49:48 PDT
<pre contentEditable="true">copyAndPasteMe</pre> results in: 

<pre style="border:1px solid black">
	<pre style="border: 1px solid black; ">
copyAndPasteMe
	</pre>
</pre>

when copyAndPasteMe is selected/copied/pasted

Visually same result: 
<div style="white-space:pre" contentEditable="true">copyAndPasteMe</div>

so there is no workaround

Note that it works well when pasting as plain text.

Online example: http://coderun.com/ide/ (create a file and copy/paste)

Not sure when this started, tested in Chrome 19+
Comment 1 jaroslav.benc 2012-05-23 18:50:32 PDT
Created attachment 143701 [details]
test case
Comment 2 Ryosuke Niwa 2012-06-28 12:22:18 PDT
The problem here is that pre has contenteditable so:

    if ((selectionStartWasStartOfParagraph && selectionEndWasEndOfParagraph && !startIsInsideMailBlockquote) ||
        startBlock == currentRoot || isListItem(startBlock) || selectionIsPlainText)
        m_preventNesting = false;

sets m_preventNesting false because startBlock is currentRoot. We should probably not set m_preventNesting false here in this case, and do this check later when we actually try to prevent nesting.
Comment 3 Ryosuke Niwa 2012-06-28 22:44:41 PDT
Actually, all we need to do is to fix the FIXME added in:
http://trac.webkit.org/changeset/98899/trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
Comment 4 Ryosuke Niwa 2012-07-11 10:20:42 PDT
Created attachment 151728 [details]
work in progress
Comment 5 Ahmad Saleem 2022-05-31 15:37:35 PDT
I am not able to reproduce this bug in Safari 15.5 on macOS 12.4. It matches other browsers.

Chrome Canary 104 - no <pre> or extra line added.
Firefox Nightly - no <pre> or extra line added.

It might have been fixed over the course or if I am testing it incorrectly, please retest accordingly. Else it can be marked as "RESOLVED CONFIGURATION CHANGED". Thanks!
Comment 6 Alexey Proskuryakov 2022-05-31 20:24:51 PDT
I'm still getting the expected behavior from Firefox 101, but not from Safari or Chrome.