Commit c7913a8a authored by Anupam Snigdha's avatar Anupam Snigdha Committed by Commit Bot

Fix indenting when paragraphs wrapped with inline elements.

When the inline elements are wrapped around nested block elements
or line breaks, |CompositeEditCommand::CloneParagraphUnderNewElement|
clones the entire inline element without taking the block elements
into consideration and then copies into <div> that is inside a
<blockquote> element. This leads to duplication of content.
Fix is to check for this scenario and properly split the elements
so the contents are not copied incorrectly.

Test: web_tests/editing/execCommand/indent/indent_blockquote_with_inline_nested_paragraphs.html

Change-Id: I63bf0af34ea2fa8a89003d1a0090a3ad453bf1e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536933Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Anupam Snigdha <snianu@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#827209}
parent 4fe38f16
...@@ -173,6 +173,42 @@ void IndentOutdentCommand::IndentIntoBlockquote(const Position& start, ...@@ -173,6 +173,42 @@ void IndentOutdentCommand::IndentIntoBlockquote(const Position& start,
? start.ComputeContainerNode() ? start.ComputeContainerNode()
: SplitTreeToNode(start.ComputeContainerNode(), element_to_split_to); : SplitTreeToNode(start.ComputeContainerNode(), element_to_split_to);
GetDocument().UpdateStyleAndLayout(DocumentUpdateReason::kEditing);
// Before moving the paragraph under the new blockquote, make sure that there
// aren't any nested paragraphs or line breaks under the outer_block. If there
// are then split it into its own block so it doesn't copy multiple
// paragraphs.
Node* highest_inline_node = HighestEnclosingNodeOfType(
end, IsInline, kCannotCrossEditingBoundary, outer_block);
if (highest_inline_node) {
Position next_position = MostForwardCaretPosition(
NextPositionOf(CreateVisiblePosition(end)).DeepEquivalent());
if (IsStartOfParagraph(CreateVisiblePosition(next_position)) &&
next_position.AnchorNode()->IsDescendantOf(highest_inline_node)) {
// <div>Line <blockquote>
// <div>
// <span> 1<div>Line 2</div></span> -> Line<span> 1</span>
// </div>
// </div> </blockquote>
// <div><span><div>Line
// 2</div></span></div>
// <div>Line <blockquote>
// <span> 1<br>Line 2</span> -> Line<span> 1</span>
// </div> </blockquote>
// <div><span>Line
// 2</span></div>
Node* split_point = HighestEnclosingNodeOfType(
next_position, IsEnclosingBlock, kCannotCrossEditingBoundary,
highest_inline_node);
split_point =
split_point ? split_point
: HighestEnclosingNodeOfType(next_position, IsInline,
kCannotCrossEditingBoundary,
highest_inline_node);
// Split the element to separate the paragraphs.
SplitElement(DynamicTo<Element>(highest_inline_node), split_point);
}
}
GetDocument().UpdateStyleAndLayout(DocumentUpdateReason::kEditing); GetDocument().UpdateStyleAndLayout(DocumentUpdateReason::kEditing);
VisiblePosition start_of_contents = CreateVisiblePosition(start); VisiblePosition start_of_contents = CreateVisiblePosition(start);
if (!target_blockquote) { if (!target_blockquote) {
......
<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
selection_test(
[
'<div contenteditable>',
'<div>Line|<span> 1<div><div>Line 2</div></div></span></div>',
'</div>',
],
'indent',
[
'<div contenteditable>',
'<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">',
'<div>Line|<span> 1</span></div></blockquote><div><span><div><div>Line 2',
'</div></div></span></div>',
'</div>',
],
'Indent content enclosed inside inline separated by nested divs');
selection_test(
[
'<div contenteditable>',
'<div>Line|<span> 1<div>Line 2</div></span></div>',
'</div>',
],
'indent',
[
'<div contenteditable>',
'<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">',
'<div>Line|<span> 1</span></div></blockquote><div><span><div>Line 2',
'</div></span></div>',
'</div>',
],
'Indent content enclosed inside inline separated by div');
selection_test(
[
'<div contenteditable>',
'<div>Line|<span> 1<br/>Line 2</span></div>',
'</div>',
],
'indent',
[
'<div contenteditable>',
'<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">',
'<div>Line|<span> 1<br></span></div></blockquote><div><span>Line 2',
'</span></div>',
'</div>',
],
'Indent content enclosed inside inline separated by br');
selection_test(
[
'<div contenteditable>',
'<div>Line|<span> 1<div><i>Line 2</i></div></span></div>',
'</div>',
],
'indent',
[
'<div contenteditable>',
'<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">',
'<div>Line|<span> 1</span></div></blockquote><div><span><div><i>Line 2',
'</i></div></span></div>',
'</div>',
],
'Indent content enclosed inside inline separated by div and inline elements');
selection_test(
[
'<div contenteditable>',
'<div>Line|<span> 1<br/><i>Line 2</i></span></div>',
'</div>',
],
'indent',
[
'<div contenteditable>',
'<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">',
'<div>Line|<span> 1<br></span></div></blockquote><div><span><i>Line 2',
'</i></span></div>',
'</div>',
],
'Indent content enclosed inside inline separated by br and inline elements');
</script>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment