Commit 20b5f338 authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Fix multiline incremental insertion

The previous fixing attempt for multiline insertion
(http://crrev.com/2680733002) only worked for two-line text, and this CL
allows for incremental insertion of three or more lines of text.

Since selection is shifted after insertion, we need to update the
selection start offset that will be used in adjusting selection for
incremental insertion.

BUG=712380

Change-Id: Ibb3212bd78fc7e30232aaa6b780c0c1182b63d1c
Reviewed-on: https://chromium-review.googlesource.com/580496
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488616}
parent 2a363a8c
......@@ -391,12 +391,13 @@ TEST_F(InputMethodControllerTest, InsertTextWithNewLineIncrementally) {
InsertHTMLElement("<div id='sample' contenteditable></div>", "sample");
Vector<CompositionUnderline> underlines;
underlines.push_back(CompositionUnderline(0, 11, Color(255, 0, 0), false, 0));
Controller().SetComposition("foo", underlines, 0, 2);
EXPECT_STREQ("foo", div->innerHTML().Utf8().data());
Controller().CommitText("a", underlines, 0);
Controller().SetComposition("bcd", underlines, 0, 2);
EXPECT_STREQ("abcd", div->innerHTML().Utf8().data());
Controller().CommitText(String("hello\nworld"), underlines, 0);
EXPECT_STREQ("hello<div>world</div>", div->innerHTML().Utf8().data());
Controller().CommitText(String("bcd\nefgh\nijkl"), underlines, 0);
EXPECT_STREQ("abcd<div>efgh</div><div>ijkl</div>",
div->innerHTML().Utf8().data());
}
TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) {
......
......@@ -280,6 +280,7 @@ void TypingCommand::InsertText(Document& document,
void TypingCommand::AdjustSelectionAfterIncrementalInsertion(
LocalFrame* frame,
const size_t selection_start,
const size_t text_length) {
if (!IsIncrementalInsertion())
return;
......@@ -293,9 +294,9 @@ void TypingCommand::AdjustSelectionAfterIncrementalInsertion(
.RootEditableElement();
DCHECK(element);
const size_t end = selection_start_ + text_length;
const size_t end = selection_start + text_length;
const size_t start =
CompositionType() == kTextCompositionUpdate ? selection_start_ : end;
CompositionType() == kTextCompositionUpdate ? selection_start : end;
const SelectionInDOMTree& selection =
CreateSelection(start, end, EndingSelection().IsDirectional(), element);
......@@ -545,6 +546,7 @@ void TypingCommand::InsertText(const String& text,
InsertTextRunWithoutNewlines(text, select_inserted_text, editing_state);
return;
}
size_t selection_start = selection_start_;
// FIXME: Need to implement selectInsertedText for cases where more than one
// insert is involved. This requires support from insertTextRunWithoutNewlines
// and insertParagraphSeparator for extending an existing selection; at the
......@@ -562,8 +564,9 @@ void TypingCommand::InsertText(const String& text,
if (editing_state->IsAborted())
return;
AdjustSelectionAfterIncrementalInsertion(GetDocument().GetFrame(),
insertion_length);
AdjustSelectionAfterIncrementalInsertion(
GetDocument().GetFrame(), selection_start, insertion_length);
selection_start += insertion_length;
}
InsertParagraphSeparator(editing_state);
......@@ -571,6 +574,7 @@ void TypingCommand::InsertText(const String& text,
return;
offset = newline + 1;
++selection_start;
}
if (!offset) {
......@@ -579,7 +583,7 @@ void TypingCommand::InsertText(const String& text,
return;
AdjustSelectionAfterIncrementalInsertion(GetDocument().GetFrame(),
text.length());
selection_start, text.length());
return;
}
......@@ -591,7 +595,7 @@ void TypingCommand::InsertText(const String& text,
return;
AdjustSelectionAfterIncrementalInsertion(GetDocument().GetFrame(),
insertion_length);
selection_start, insertion_length);
}
}
......
......@@ -101,6 +101,7 @@ class CORE_EXPORT TypingCommand final : public CompositeEditCommand {
composition_type_ = type;
}
void AdjustSelectionAfterIncrementalInsertion(LocalFrame*,
const size_t selection_start,
const size_t text_length);
ETypingCommand CommandTypeOfOpenCommand() const { return command_type_; }
......
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