<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+
Created attachment 143701 [details] test case
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.
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
Created attachment 151728 [details] work in progress
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!
I'm still getting the expected behavior from Firefox 101, but not from Safari or Chrome.