Reviewed by Oliver Hunt.
<rdar://problem/
5482023> GoogleDocs: After FormatBlock in an empty document, certain functions are disabled
We were trying to insert a block of the requested type before the body element.
* editing/FormatBlockCommand.cpp:
(WebCore::FormatBlockCommand::doApply):
Removed unnecessary ()s in the if condition.
Removed "|| !upstreamStart.node()->isDescendantOf(root)" from the if condition, since
a) upstreamStart will never be outside the root editable element, since in that case
there would be no block inside the editable root to Format, and b) if upstreamStart.node()
*is* the root, then refNode is the root, and we shouldn't insert before the root, we should insert
at [root, 0].
Added comments to explain the use of upstream() in the second if-clause.
Added an early return for case where there is nothing selected, in that case, there is nothing
to move.
LayoutTests:
Reviewed by Oliver Hunt.
<rdar://problem/
5482023> GoogleDocs: After performing FormatBlock in an empty document, certain functions are disabled
* editing/execCommand/
5482023.html: Added.
* platform/mac/editing/execCommand/
5482023-expected.checksum: Added.
* platform/mac/editing/execCommand/
5482023-expected.png: Added.
* platform/mac/editing/execCommand/
5482023-expected.txt: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28611
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-12-10 Justin Garcia <justin.garcia@apple.com>
+
+ Reviewed by Oliver Hunt.
+
+ <rdar://problem/5482023> GoogleDocs: After performing FormatBlock in an empty document, certain functions are disabled
+
+ * editing/execCommand/5482023.html: Added.
+ * platform/mac/editing/execCommand/5482023-expected.checksum: Added.
+ * platform/mac/editing/execCommand/5482023-expected.png: Added.
+ * platform/mac/editing/execCommand/5482023-expected.txt: Added.
+
2007-12-10 Darin Adler <darin@apple.com>
Reviewed by Sam Weinig.
--- /dev/null
+<head>
+<script>
+function runTest() {
+ document.body.focus();
+ document.execCommand("FormatBlock", false, "h1");
+ document.execCommand("InsertText", false, "This tests for a bug when performing a FormatBlock inside a body with no visible content. This text should be inside an h1 element.");
+}
+</script>
+</head>
+<body onload="runTest();" contenteditable="true">
+</body>
\ No newline at end of file
--- /dev/null
+5b84455378b756fc872ae48aef37a3d3
\ No newline at end of file
--- /dev/null
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x571
+ RenderBlock {H1} at (0,0) size 784x111
+ RenderText {#text} at (0,0) size 784x111
+ text run at (0,0) width 729: "This tests for a bug when performing a FormatBlock "
+ text run at (0,37) width 779: "inside a body with no visible content. This text should be"
+ text run at (779,37) width 5: " "
+ text run at (0,74) width 287: "inside an h1 element."
+caret: position 132 of child 0 {#text} of child 0 {H1} of child 1 {BODY} of child 0 {HTML} of document
+2007-12-10 Justin Garcia <justin.garcia@apple.com>
+
+ Reviewed by Oliver Hunt.
+
+ <rdar://problem/5482023> GoogleDocs: After FormatBlock in an empty document, certain functions are disabled
+
+ We were trying to insert a block of the requested type before the body element.
+
+ * editing/FormatBlockCommand.cpp:
+ (WebCore::FormatBlockCommand::doApply):
+ Removed unnecessary ()s in the if condition.
+ Removed "|| !upstreamStart.node()->isDescendantOf(root)" from the if condition, since
+ a) upstreamStart will never be outside the root editable element, since in that case
+ there would be no block inside the editable root to Format, and b) if upstreamStart.node()
+ *is* the root, then refNode is the root, and we shouldn't insert before the root, we should insert
+ at [root, 0].
+ Added comments to explain the use of upstream() in the second if-clause.
+ Added an early return for case where there is nothing selected, in that case, there is nothing
+ to move.
+
2007-12-10 Adele Peterson <adele@apple.com>
Reviewed and partially fixed by Tim Hatcher.
RefPtr<Node> placeholder = createBreakElement(document());
Node* root = endingSelection().start().node()->rootEditableElement();
- if (refNode == root || root->isDescendantOf(refNode))
- refNode = paragraphStart.deepEquivalent().node();
-
- Position upstreamStart = paragraphStart.deepEquivalent().upstream();
- if ((validBlockTag(refNode->nodeName().lower()) && paragraphStart == blockStart && paragraphEnd == blockEnd) ||
- !upstreamStart.node()->isDescendantOf(root))
+ if (validBlockTag(refNode->nodeName().lower()) &&
+ paragraphStart == blockStart && paragraphEnd == blockEnd &&
+ refNode != root && !root->isDescendantOf(refNode))
// Already in a valid block tag that only contains the current paragraph, so we can swap with the new tag
insertNodeBefore(blockNode.get(), refNode);
else {
- insertNodeAt(blockNode.get(), upstreamStart);
+ // Avoid inserting inside inline elements that surround paragraphStart with upstream().
+ // This is only to avoid creating bloated markup.
+ insertNodeAt(blockNode.get(), paragraphStart.deepEquivalent().upstream());
}
appendNode(placeholder.get(), blockNode.get());
- moveParagraph(paragraphStart, paragraphEnd, VisiblePosition(Position(placeholder.get(), 0)), true, false);
+
+ VisiblePosition destination(Position(placeholder.get(), 0));
+ if (paragraphStart == paragraphEnd) {
+ setEndingSelection(destination);
+ return;
+ }
+ moveParagraph(paragraphStart, paragraphEnd, destination, true, false);
}
}