+2004-12-10 Ken Kocienda <kocienda@apple.com>
+
+ Reviewed by Darin
+
+ Fix for this bug:
+
+ <rdar://problem/3915047> HItting return in empty document inserts <p> but
+ insertion point does not move
+
+ * khtml/editing/htmlediting.cpp:
+ (khtml::InsertParagraphSeparatorCommand::doApply): The issue is that the
+ code to insert the <p> element for the return is not detecting the fact
+ that the document is empty. Inserting a <p> into an empty body will not
+ "add a new line" as the user expects. With this change, we'll add a second
+ <p> when the root editable element has no rendered kids.
+
2004-12-10 Maciej Stachowiak <mjs@apple.com>
Reviewed by John.
// If the start block is the body, just make a P tag, otherwise, make a shallow clone
// of the the start block.
NodeImpl *addedBlock = 0;
- if (startBlock->id() == ID_BODY) {
+ if (startBlock == startBlock->rootEditableElement()) {
int exceptionCode = 0;
+ if (startBlock->renderer() && !startBlock->renderer()->firstChild()) {
+ // No rendered kids in the root editable element.
+ // Just inserting a <p> in this situation is not enough, since this operation
+ // is supposed to add an additional user-visible line to the content.
+ // So, insert an extra <p> to make the one we insert right appear as the second
+ // line in the root editable element.
+ NodeImpl *extraBlock = document()->createHTMLElement("P", exceptionCode);
+ ASSERT(exceptionCode == 0);
+ appendNode(extraBlock, startBlock);
+ extraBlock->ref();
+ insertBlockPlaceholderIfNeeded(extraBlock);
+ clonedNodes.append(extraBlock);
+ }
addedBlock = document()->createHTMLElement("P", exceptionCode);
ASSERT(exceptionCode == 0);
appendNode(addedBlock, startBlock);