Skip to content

Commit

Permalink
[editing] Make DeleteInsignificantText() to handle spaces causing lin…
Browse files Browse the repository at this point in the history
…e break

This patch changes `CompositeEditCommand::DeleteInsignificantText()`
not to remove `Text` node causing line break.

`Text` node causes line break should be significant because it can be
rendered when it doesn't cause line break afer changing something
around it.

Bug: 1322746
Change-Id: I2ba431d7d8e3406d5cb2249b4bb36f2263434a5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3817426
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1034947}
  • Loading branch information
yosinch authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent 4d7cf2e commit 114bec7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,14 @@ void CompositeEditCommand::RebalanceWhitespace() {
RebalanceWhitespaceAt(selection.End());
}

static bool IsInsignificantText(const LayoutText& layout_text) {
if (layout_text.HasInlineFragments())
return false;
// Spaces causing line break don't have `NGFragmentItem` but it has
// non-zero length. See http://crbug.com/1322746
return !layout_text.ResolvedTextLength();
}

void CompositeEditCommand::DeleteInsignificantText(Text* text_node,
unsigned start,
unsigned end) {
Expand All @@ -843,7 +851,7 @@ void CompositeEditCommand::DeleteInsignificantText(Text* text_node,
if (!text_layout_object)
return;

if (!text_layout_object->HasInlineFragments()) {
if (IsInsignificantText(*text_layout_object)) {
// whole text node is empty
// Removing a Text node won't dispatch synchronous events.
RemoveNode(text_node, ASSERT_NO_EDITING_ABORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ namespace blink {

class TypingCommandTest : public EditingTestBase {};

// http://crbug.com/1322746
TEST_F(TypingCommandTest, DeleteInsignificantText) {
InsertStyleElement(
"b { display: inline-block; width: 100px; }"
"div { width: 100px; }");
Selection().SetSelection(
SetSelectionTextToBody("<div contenteditable>"
"|<b><pre></pre></b> <a>abc</a>"
"</div>"),
SetSelectionOptions());
EditingState editing_state;
TypingCommand::ForwardDeleteKeyPressed(GetDocument(), &editing_state);
ASSERT_FALSE(editing_state.IsAborted());

EXPECT_EQ(
u8"<div contenteditable>"
"|\u00A0<a>abc</a>"
"</div>",
GetSelectionTextFromBody());
}

// This is a regression test for https://crbug.com/585048
TEST_F(TypingCommandTest, insertLineBreakWithIllFormedHTML) {
SetBodyContent("<div contenteditable></div>");
Expand Down

0 comments on commit 114bec7

Please sign in to comment.