Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1554)

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 1847583003: Fix setComposingText when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid using innerText() Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/InputMethodController.cpp
diff --git a/third_party/WebKit/Source/core/editing/InputMethodController.cpp b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
index 0d88e0f740a014a088b732b6340f8ca8bef0e15e..fef659aba5f2fa9f134d9a4d440d94d7aca6af3a 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -239,7 +239,7 @@ void InputMethodController::cancelCompositionIfSelectionIsInvalid()
frame().chromeClient().didCancelCompositionOnSelectionChange();
}
-void InputMethodController::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd)
+void InputMethodController::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, int selectionStart, int selectionEnd)
{
Editor::RevealSelectionScope revealSelectionScope(&editor());
@@ -332,9 +332,24 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp
if (baseNode->layoutObject())
baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
- unsigned start = std::min(baseOffset + selectionStart, extentOffset);
- unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOffset);
- Range* selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end);
+ // In case of exceeding the left boundary.
+ int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start());
+ int start = std::max(selectionOffsetsStart + selectionStart, 0);
+ int end = std::max(selectionOffsetsStart + selectionEnd, start);
+
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ if (!rootEditableElement)
+ return;
+
+ // In case of exceeding the right boundary.
+ // If both |value1| and |value2| exceed right boundary,
+ // PlainTextRange(value1, value2)::createRange() will return a default
+ // value, which is [0,0]. In order to get the right boundary in that case,
+ // we should make sure |value1| is within range at least.
+ const EphemeralRange startRange = PlainTextRange(0, start).createRange(*rootEditableElement);
aelias_OOO_until_Jul13 2016/05/10 20:44:11 These ranges are odd, wouldn't it have the same ef
yabinh 2016/05/11 00:28:38 That's right. But in order to create Position obje
aelias_OOO_until_Jul13 2016/05/11 02:49:35 OK, it looks like the algorithm in createRange() i
yosin_UTC9 2016/05/11 05:53:23 nit: s/const EphemeralRange/const EphemeralRange&/
+ const EphemeralRange endRange = PlainTextRange(0, end).createRange(*rootEditableElement);
yosin_UTC9 2016/05/11 05:53:23 nit: s/const EphemeralRange/const EphemeralRange&/
+
+ Range* selectedRange = Range::create(rootEditableElement->document(), startRange.endPosition(), endRange.endPosition());
frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
if (underlines.isEmpty()) {

Powered by Google App Engine
This is Rietveld 408576698