summaryrefslogtreecommitdiffstats
path: root/WebCore/editing/InsertParagraphSeparatorCommand.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-02-15 12:23:52 +0000
committerSteve Block <steveblock@google.com>2010-02-16 11:48:32 +0000
commit8a0914b749bbe7da7768e07a7db5c6d4bb09472b (patch)
tree73f9065f370435d6fde32ae129d458a8c77c8dff /WebCore/editing/InsertParagraphSeparatorCommand.cpp
parentbf14be70295513b8076f3fa47a268a7e42b2c478 (diff)
downloadexternal_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.zip
external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.tar.gz
external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.tar.bz2
Merge webkit.org at r54731 : Initial merge by git
Change-Id: Ia79977b6cf3b0b00c06ef39419989b28e57e4f4a
Diffstat (limited to 'WebCore/editing/InsertParagraphSeparatorCommand.cpp')
-rw-r--r--WebCore/editing/InsertParagraphSeparatorCommand.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/WebCore/editing/InsertParagraphSeparatorCommand.cpp b/WebCore/editing/InsertParagraphSeparatorCommand.cpp
index 695f46a..058b961 100644
--- a/WebCore/editing/InsertParagraphSeparatorCommand.cpp
+++ b/WebCore/editing/InsertParagraphSeparatorCommand.cpp
@@ -44,6 +44,22 @@ namespace WebCore {
using namespace HTMLNames;
+// When inserting a new line, we want to avoid nesting empty divs if we can. Otherwise, when
+// pasting, it's easy to have each new line be a div deeper than the previous. E.g., in the case
+// below, we want to insert at ^ instead of |.
+// <div>foo<div>bar</div>|</div>^
+static Element* highestVisuallyEquivalentDiv(Element* startBlock)
+{
+ Element* curBlock = startBlock;
+ while (!curBlock->nextSibling() && curBlock->parentElement()->hasTagName(divTag)) {
+ NamedNodeMap* attributes = curBlock->parentElement()->attributes(true);
+ if (attributes && !attributes->isEmpty())
+ break;
+ curBlock = curBlock->parentElement();
+ }
+ return curBlock;
+}
+
InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document *document, bool mustUseDefaultParagraphElement)
: CompositeEditCommand(document)
, m_mustUseDefaultParagraphElement(mustUseDefaultParagraphElement)
@@ -214,7 +230,13 @@ void InsertParagraphSeparatorCommand::doApply()
// When inserting the newline after the blockquote, we don't want to apply the original style after the insertion
shouldApplyStyleAfterInsertion = false;
}
- insertNodeAfter(blockToInsert, startBlock);
+
+ // Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists). However,
+ // for div nodes, this can result in nested div tags that are hard to break out of.
+ Element* siblingNode = startBlock;
+ if (blockToInsert->hasTagName(divTag))
+ siblingNode = highestVisuallyEquivalentDiv(startBlock);
+ insertNodeAfter(blockToInsert, siblingNode);
}
// Recreate the same structure in the new paragraph.