Fix for this bug:
<rdar://problem/
3786362> REGRESSION (Mail): pasted text loses one newline
* khtml/editing/htmlediting.cpp:
(khtml::InsertLineBreakCommand::doApply): Added check for strict mode before adding an extra br element
at the end of a block. This is only necessary in quirks mode. Also, lower-case "br" used to make element.
(khtml::ReplaceSelectionCommand::doApply): If the replacement adds a br element as the last element
in a block and the document is in quirks mode, add an additional br to make the one in the
replacement content show up. This turns out to be much the same logic as is done in InsertLineBreakCommand.
* layout-tests/editing/inserting/insert-
3786362-fix-expected.txt: Added.
* layout-tests/editing/inserting/insert-
3786362-fix.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8108
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
--- /dev/null
+layer at (0,0) size 800x600
+ RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x584
+ RenderBlock {DIV} at (0,0) size 784x88 [border: (2px solid #FF0000)]
+ RenderText {TEXT} at (2,2) size 11x28
+ text run at (2,2) width 11: "a"
+ RenderBR {BR} at (0,0) size 0x0
+ RenderBR {BR} at (2,30) size 0x28
+ RenderText {TEXT} at (2,58) size 12x28
+ text run at (2,58) width 12: "b"
+ RenderBlock {DIV} at (0,88) size 784x88 [border: (2px solid #FF0000)]
+ RenderText {TEXT} at (2,2) size 11x28
+ text run at (2,2) width 11: "a"
+ RenderBR {BR} at (0,0) size 0x0
+ RenderBR {BR} at (2,30) size 0x28
+ RenderBR {BR} at (2,58) size 0x28
+selection is CARET:
+start: position 0 of child 4 {BR} of child 3 {DIV} of root {BODY}
+upstream: position 1 of child 3 {BR} of child 3 {DIV} of root {BODY}
+downstream: position 0 of child 4 {BR} of child 3 {DIV} of root {BODY}
--- /dev/null
+<html>
+<head>
+
+<style>
+.editing {
+ border: 2px solid red;
+ font-size: 24px;
+ word-wrap: break-word;
+ -khtml-nbsp-mode: space;
+ -khtml-line-break: after-white-space;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+ extendSelectionForwardByLineCommand();
+ extendSelectionForwardByLineCommand();
+ copyCommand();
+ moveSelectionForwardByLineCommand();
+ moveSelectionForwardByLineCommand();
+ pasteCommand();
+}
+
+</script>
+
+<title>Editing Test</title>
+</head>
+<body contenteditable id="root">
+<div class="editing" id="test">a<br><br>b</div>
+<div class="editing"></div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
+2004-12-02 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by John
+
+ Fix for this bug:
+
+ <rdar://problem/3786362> REGRESSION (Mail): pasted text loses one newline
+
+ * khtml/editing/htmlediting.cpp:
+ (khtml::InsertLineBreakCommand::doApply): Added check for strict mode before adding an extra br element
+ at the end of a block. This is only necessary in quirks mode. Also, lower-case "br" used to make element.
+ (khtml::ReplaceSelectionCommand::doApply): If the replacement adds a br element as the last element
+ in a block and the document is in quirks mode, add an additional br to make the one in the
+ replacement content show up. This turns out to be much the same logic as is done in InsertLineBreakCommand.
+ * layout-tests/editing/inserting/insert-3786362-fix-expected.txt: Added.
+ * layout-tests/editing/inserting/insert-3786362-fix.html: Added.
+
2004-12-02 Richard Williamson <rjw@apple.com>
Fixed <rdar://problem/3841332> REGRESSION (125.9-167u): repro crash in -[KWQPageState invalidate] involving .Mac images
if (hasTrailingBR) {
setEndingSelection(Position(next, 0));
}
- else {
+ else if (!document()->inStrictMode()) {
// Insert an "extra" BR at the end of the block.
- ElementImpl *extraBreakNode = document()->createHTMLElement("BR", exceptionCode);
+ ElementImpl *extraBreakNode = document()->createHTMLElement("br", exceptionCode);
ASSERT(exceptionCode == 0);
insertNodeAfter(extraBreakNode, nodeToInsert);
setEndingSelection(Position(extraBreakNode, 0));
completeHTMLReplacement(startPos, endPos);
}
else {
+ if (lastNodeInserted->id() == ID_BR && !document()->inStrictMode()) {
+ document()->updateLayout();
+ VisiblePosition pos(Position(lastNodeInserted, 0));
+ if (isLastVisiblePositionInBlock(pos)) {
+ NodeImpl *next = lastNodeInserted->traverseNextNode();
+ bool hasTrailingBR = next && next->id() == ID_BR && lastNodeInserted->enclosingBlockFlowElement() == next->enclosingBlockFlowElement();
+ if (!hasTrailingBR) {
+ // Insert an "extra" BR at the end of the block.
+ int exceptionCode = 0;
+ ElementImpl *extraBreakNode = document()->createHTMLElement("br", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ insertNodeBefore(extraBreakNode, lastNodeInserted);
+ }
+ }
+ }
completeHTMLReplacement(firstNodeInserted, lastNodeInserted);
}
}