Commit e8805a4e authored by Tessa Nijssen's avatar Tessa Nijssen Committed by Commit Bot

Editor::ReplaceSelection() Sets Smart Replace to False

Editor::ReplaceSelection() was modified so that |smart_replace| is
false. No callers currently existed that used the version of
ReplaceSelection() with |smart_replace| = true.

Smart Replace may add whitespace before and/or after an inserted
piece of text. The only current call to Editor::ReplaceSelection()
needs |smart_replace| to be false because no extra whitespace is
desired.

A comment was added in editor.h to explain that Smart Replace is not
used in Editor::ReplaceSelection().

A test was added, EditorTest.ReplaceSelection, which passes when
|smart_replace| = false and fails when |smart_replace| = true.

Bug: 717553
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I1424e200780cd32900dac5b6f824f8d50c3f8dd5
Reviewed-on: https://chromium-review.googlesource.com/1150448
Commit-Queue: Tessa Nijssen <tnijssen@google.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarSarah Chan <spqchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580940}
parent 0c234193
......@@ -931,7 +931,7 @@ void Editor::ToggleOverwriteModeEnabled() {
void Editor::ReplaceSelection(const String& text) {
DCHECK(!GetFrame().GetDocument()->NeedsLayoutTreeUpdate());
bool select_replacement = Behavior().ShouldSelectReplacement();
bool smart_replace = true;
bool smart_replace = false;
ReplaceSelectionWithText(text, select_replacement, smart_replace,
InputEvent::InputType::kInsertReplacementText);
}
......
......@@ -193,7 +193,8 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> {
bool smart_replace,
InputEvent::InputType);
// Implementation of WebLocalFrameImpl::replaceSelection.
// Implementation of WebLocalFrameImpl::ReplaceSelection. Does not use smart
// replacement.
void ReplaceSelection(const String&);
void ReplaceSelectionAfterDragging(DocumentFragment*,
......
......@@ -91,4 +91,19 @@ TEST_F(EditorTest, DontCopyHiddenSelections) {
EXPECT_TRUE(copied.IsEmpty()) << copied << " was copied.";
}
TEST_F(EditorTest, ReplaceSelection) {
const char* body_content = "<input id=text value='HELLO'>";
SetBodyContent(body_content);
HTMLInputElement& text_control =
ToHTMLInputElement(*GetDocument().getElementById("text"));
text_control.select();
text_control.SetSelectionRange(2, 2);
Editor& editor = GetDocument().GetFrame()->GetEditor();
editor.ReplaceSelection("NEW");
EXPECT_EQ("HENEWLLO", text_control.value());
}
} // 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