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

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: Add some C++ unit tests. Created 4 years, 8 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 7ba773eeecf9725bd28a2496d69507aed2ddaaac..f0b98b970c5743c2a82e53a2d1f64709898bd006 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -234,7 +234,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());
@@ -322,10 +322,18 @@ 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);
- RawPtr<Range> selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end);
- frame().selection().setSelectedRange(selectedRange.get(), TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
+ // The case when cursor position exceeds left boundary is handled here
+ int start = std::max(static_cast<int>(baseOffset) + selectionStart, 0);
+ int end = std::max(static_cast<int>(baseOffset) + selectionEnd, start);
+
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ if (!rootEditableElement)
+ return;
+
+ // The case when cursor position exceeds right boundary is handled here
+ const EphemeralRange selectedRange = PlainTextRange(start, end).createRange(*rootEditableElement);
+
+ frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
if (underlines.isEmpty()) {
frame().document()->markers().addCompositionMarker(m_compositionRange->startPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTheme::theme().platformDefaultCompositionBackgroundColor());

Powered by Google App Engine
This is Rietveld 408576698