Commit 89209614 authored by yosin's avatar yosin Committed by Commit bot

Make InsertTextCommand not to apply typing style for empty selection

This patch makes |InsertTextCommand::DoApply()| not to call |ApplyStyle()| for
applying typing style when selection after inserting text is empty since
|ApplyStyle()| doesn't work with empty selection.

The issue 714311 and the attached test case insert text into OPTION element to
get empty selection after insertion, since we can't place selection inside
OPTION element.

BUG=714311
TEST=run_webkit_unit_tests --gtest_filter=InsertTextCommandTest.WithTypingStyle

Review-Url: https://codereview.chromium.org/2847763004
Cr-Commit-Position: refs/heads/master@{#468080}
parent cff98375
......@@ -285,6 +285,7 @@ source_set("unit_tests") {
"commands/DeleteSelectionCommandTest.cpp",
"commands/InsertIncrementalTextCommandTest.cpp",
"commands/InsertListCommandTest.cpp",
"commands/InsertTextCommandTest.cpp",
"commands/ReplaceSelectionCommandTest.cpp",
"commands/SetCharacterDataCommandTest.cpp",
"commands/SplitTextNodeCommandTest.cpp",
......
......@@ -276,7 +276,7 @@ void InsertTextCommand::DoApply(EditingState* editing_state) {
GetDocument().GetFrame()->GetEditor().TypingStyle()) {
typing_style->PrepareToApplyAt(end_position,
EditingStyle::kPreserveWritingDirection);
if (!typing_style->IsEmpty()) {
if (!typing_style->IsEmpty() && !EndingSelection().IsNone()) {
ApplyStyle(typing_style, editing_state);
if (editing_state->IsAborted())
return;
......
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/editing/commands/InsertTextCommand.h"
#include "core/editing/EditingTestBase.h"
#include "core/editing/FrameSelection.h"
namespace blink {
class InsertTextCommandTest : public EditingTestBase {};
// http://crbug.com/714311
TEST_F(InsertTextCommandTest, WithTypingStyle) {
SetBodyContent("<div contenteditable=true><option id=sample></option></div>");
Element* const sample = GetDocument().getElementById("sample");
Selection().SetSelection(
SelectionInDOMTree::Builder().Collapse(Position(sample, 0)).Build());
// Register typing style to make |InsertTextCommand| to attempt to apply
// style to inserted text.
GetDocument().execCommand("fontSizeDelta", false, "+3", ASSERT_NO_EXCEPTION);
CompositeEditCommand* const command =
InsertTextCommand::Create(GetDocument(), "x");
command->Apply();
EXPECT_EQ(
"<div contenteditable=\"true\"><option id=\"sample\">x</option></div>",
GetDocument().body()->innerHTML())
<< "Content of OPTION is distributed into shadow node as text"
"without applying typing style.";
}
} // namespace blink
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