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

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: For multiple nodes. 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..1db29aa05f7b914a40c966144643b758c0d9040a 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,25 @@ 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 start = std::max(static_cast<int>(getSelectionOffsets().start()) + selectionStart, 0);
+ int end = std::max(static_cast<int>(getSelectionOffsets().start()) + selectionEnd, start);
+
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ if (!rootEditableElement)
+ return;
+
+ // In case of exceeding the right boundary.
+ const EphemeralRange startRange = PlainTextRange(0, start).createRange(*rootEditableElement);
Changwan Ryu 2016/05/09 12:52:23 You can create only range to handle both: const E
yabinh 2016/05/09 13:02:50 If both number1 and number2 exceed the right bound
+ const EphemeralRange endRange = PlainTextRange(0, end).createRange(*rootEditableElement);
+
+ start = startRange.endPosition().computeOffsetInContainerNode();
+ Node* startNode = startRange.endPosition().computeContainerNode();
+
+ end = endRange.endPosition().computeOffsetInContainerNode();
+ Node* endNode = endRange.endPosition().computeContainerNode();
+
+ Range* selectedRange = Range::create(rootEditableElement->document(), startNode, start, endNode, end);
frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
if (underlines.isEmpty()) {

Powered by Google App Engine
This is Rietveld 408576698