Chromium Code Reviews

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

Issue 1889053003: Fix InputConnection.deleteSurroundingText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try again. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
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 ca051a0c662ea21fe8e1dd82ca3db819b1c1d4e9..13203203de17198c325300ac71f516652e3008d3 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -472,6 +472,44 @@ void InputMethodController::extendSelectionAndDelete(int before, int after)
TypingCommand::deleteSelection(*frame().document());
}
+void InputMethodController::deleteSurroundingText(size_t before, size_t after)
+{
+ if (!editor().canEdit())
+ return;
+ PlainTextRange selectionOffsets(getSelectionOffsets());
+ if (selectionOffsets.isNull())
+ return;
+
+ size_t selectionStart = selectionOffsets.start();
+ size_t selectionEnd = selectionOffsets.end();
+
+ if (before != 0) {
+ before = std::min(selectionStart, before);
+
+ // Select the text to be deleted before selectionStart,
+ // and adjust the start of selection in case of multi-code text.
+ size_t adjustedStart = selectionStart + 1 - before;
+ const LChar* text = frame().document()->activeElement()->innerText().characters8();
+ U8_SET_CP_START(text, 0, adjustedStart);
Changwan Ryu 2016/04/25 10:21:08 This is incorrect if the given text is UTF16 strin
+ --adjustedStart;
+
+ if (!setSelectionOffsets(PlainTextRange(static_cast<int>(adjustedStart), static_cast<int>(selectionStart))))
+ return;
+ TypingCommand::deleteSelection(*frame().document());
+
+ selectionEnd = selectionEnd - (selectionStart - adjustedStart);
+ selectionStart = adjustedStart;
+ }
+
+ if (after != 0) {
+ if (!setSelectionOffsets(PlainTextRange(static_cast<int>(selectionEnd), static_cast<int>(selectionEnd + after))))
+ return;
+ TypingCommand::deleteSelection(*frame().document());
+ }
+
+ setSelectionOffsets(PlainTextRange(selectionStart, selectionEnd));
+}
+
DEFINE_TRACE(InputMethodController)
{
visitor->trace(m_frame);

Powered by Google App Engine